This program attempts to declared a variable
in an inner scope
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
/*
This program attempts to declared a variable
in an inner scope with the same name as one
defined in an outer scope.
*** This program will not compile. ***
*/
using System;
public class NestVar {
public static void Main() {
int count;
for(count = 0; count < 10; count = count+1) {
Console.WriteLine("This is count: " + count);
int count; // illegal!!!
for(count = 0; count < 2; count++)
Console.WriteLine("This program is in error!");
}
}
}
Related examples in the same category