I previously suggested that you look at the source code, but from your comments, it sounds like you are looking at MSIL-based Reflector in C #. It is important to understand that this does not necessarily bear close resemblance to the source code as written.
At the MSIL level, there is no for loop or while . There are only conditional branch instructions. (See here: http://weblogs.asp.net/kennykerr/archive/2004/09/23/introduction-to-msil-part-6-common-language-constructs.aspx ). Any tool trying to recreate C # should make a few guesses about how the code was originally created. It seems likely that this was not originally written as a for loop, but this reflector found that IL could have been generated by a for loop, and its heuristic had a poor idea that it should be a for loop, and not something else.
If I look at the same code in ILSpy, it appears as a while . This is still redundant, but looks a lot less strange. In addition, it is possible that the source code actually did what was optimized, perhaps calling the [Conditional] methods or the code marked with the #if directives. Again, perhaps the source code used to execute something other than the parts was commented out - comments were not saved in IL. Or perhaps there was more code in the past and it just left.
In short, there are many ways that you see in Reflector, which can be very different from what was originally written. You should consider this more beautiful view of IL, not the C # example, as it is written by people.
source share