23
1
using System;
2
3
class Program
4
{
5
static void Main(string[] args)
6
{
7
int count = 0;
8
9
for (int i = 0; i < 5; i++)
10
Console.WriteLine(i);
11
12
//Console.WriteLine(i); //can't access i because it has loop level scope
13
14
if (count == 0)
15
{
16
count++; //can access method variables
17
18
int x = 10; //declared block level variable
19
}
20
21
//Console.WriteLine(x); //can't access block level variable
22
}
23
}
Cached Result
Completing 0
Throwing 1
Completing 2
Throwing 3
Completing 4
Final Catching System.Exception False
Throwing 1
Completing 2
Throwing 3
Completing 4
Final Catching System.Exception False