multiple initializers in for?

  • Thread starter Thread starter Beeeeeves
  • Start date Start date
B

Beeeeeves

Is it true that in C# you can only have initializers of one type in a for
loop?
For instance I can put
for(int a = 1, b = 2; a < b; a++)

but I can't have
for(int a = 1, string b = "yo"; a < 10; a++)
 
Is it true that in C# you can only have initializers of one type in a for
loop?
For instance I can put
for(int a = 1, b = 2; a < b; a++)

but I can't have
for(int a = 1, string b = "yo"; a < 10; a++)

Well, it's trivial to test this, but yes, it's true.
 
Beeeeeves said:
Is it true that in C# you can only have initializers of one type in a for
loop?
For instance I can put
for(int a = 1, b = 2; a < b; a++)

but I can't have
for(int a = 1, string b = "yo"; a < 10; a++)

In that case you'll have to use something like:

int a;
string b;
for (a = 1, b = "yo"; a < 10; a++)
 
I know, I did test it- but I thought I was making some elementary mistake as it just seemed a bit weird.
 
Back
Top