Connecting Tech Pros Worldwide Forums | Help | Site Map

multiple initializers in for?

Beeeeeves
Guest
 
Posts: n/a
#1: Nov 16 '05
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++)



Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#2: Nov 16 '05

re: multiple initializers in for?


<"Beeeeeves" <1234512345789123456789>> wrote:[color=blue]
> 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++)[/color]

Well, it's trivial to test this, but yes, it's true.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
C# Learner
Guest
 
Posts: n/a
#3: Nov 16 '05

re: multiple initializers in for?


Beeeeeves wrote:[color=blue]
> 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++)[/color]

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

int a;
string b;
for (a = 1, b = "yo"; a < 10; a++)
Closed Thread