Skip to content

Instantly share code, notes, and snippets.

@daleth90
Last active Nov 10, 2018
Embed
What would you like to do?
using System;
namespace Playground {
class Program {
static void Main() {
int a = 30;
for ( int i = 0; i < 10; i++ ) {
Console.Write( a + i ); // 編譯通過,在這裡可以使用外層的 a 及在此 for 陳述式內宣告的 i
Console.Write( " " );
}
Console.Write( a + i + 1 ); // 編譯錯誤,因為 i 是在 for 陳述式內宣告的,到這裡已經不存在
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment