I have a nice question about the loop-expression of a for-loop in C#.
I always like to learn and extend my knowledge so I often use my reflector to look and learn from other. Lately I was looking around in an assembly which I assume is a C# assembly.
I came across this:
public virtual void DoRows(Parse rows)
{
for (; rows != null; {
Parse more;
rows = more;
}
)
{
more = rows.More;
this.DoRow(rows);
}
}
I never knew I could use a code-block in my loop-expression. So I fired up MSDN and went looking in the language reference of C# but found nothing.
The C++ reference shows some interesting things tho (http://msdn.microsoft.com/en-us/library/b80153d8.aspx), but I am not a C++ developper and I have a strong feeling the assmbly was not written in C++.
dotPeek says the assembly is a v4.0.30319 / msil assembly.
Now here are the questions: - Is this a C++ or a C# code-construct?! - Can we do things like this in C#?
I am not able to reproduce code that looks like that and compiles in VS2010.
@edit: changed the word assembly in code-construct.
@edit II: Thanks for all your answers. I think this is either a bug in the dotPeek reflector or we found some for-loop-expression easter eggs. This is what Red Gate says about the same method:
public virtual void DoRows(Parse rows)
{
while (rows != null)
{
Parse more = rows.More;
this.DoRow(rows);
rows = more;
}
}