After nearly a month, I finally completed the first chapter of learning + translation. The content in Chapter 1 is relatively basic, and most of the content can be seen as a lecture on how to develop good programming habits. In addition to the gethashcode () section, other content is commonly used programming skills. Distinguishing between reference and value types and the relationship between four equals () is also the basic knowledge of. net.
When comparing foreach and for loops in item 11: prefer foreach loops, loop 3 in the book will judge whether the array is out of bounds during the loop, which may be a problem. Msil disassembler is used to check the msil of loop 3. The check for out-of-boundary behaviors described in this document are not found. The biggest difference between them and loop 2 lies in the judgment of cyclic variables. The example is as follows:
Int [] Foo = new int [100];
// Loop 1
Foreach (int I in Foo)
{
Console. writeline (I. tostring ());
}
// Cycle 2
For (INT Index = 0; index <Foo. length; index ++)
{
Console. writeline (FOO [Index]. tostring ());
}
// Loop 3
Int Len = Foo. length;
For (INT Index = 0; index <Len; index ++)
{
Console. writeline (FOO [Index]. tostring ());
}
The following items are available now and found in the manual ....
Through msil, we can see that loop 3 does this:
Il_001d: LDC. i4.s 100
Il_001f: BLT. s il_0014
Constant 100 is pushed into the stack with a 4-byte integer, and then compared with the cyclic variable. If the value is smaller than, It is redirected to il_0014, that is, the start part of the loop. No behavior is found to determine whether the array is out of bounds.
Loop 1 and loop 2 do the following in this function:
Il_0029: ldlen
Il_002a: Conv. I4
Il_002b: BLT. s il_0017
Obtain the array length, convert it to a 4-byte integer, and then compare it. The red part is where they are. This is also consistent with the test results.
Finally, I hope you will give more valuable comments, 3x. Click the link below to go to the first chapter of the directory.
Valid C # directory