Why can't we define a variable inside a while loop?

后端 未结 6 1296
星月不相逢
星月不相逢 2020-12-03 03:27

We can do:

using (Stream s ..)

and:

for (int i ...)

Why can\'t we as well do something like:



        
6条回答
  •  生来不讨喜
    2020-12-03 03:44

    There's no inherent reason why it couldn't be done - the C# designers just chose not to allow it. It works just fine in Perl, for example ("while ((my $i = NextNum()) > 0) { ... }").

提交回复
热议问题