And the reason for this specific limitation is that it is intended to reduce
the incidence of programming errors.
Yes, it would be perfectly reasonable for the language to allow the
"redeclaration" of the variable in different bracket-scopes within the same
function, and various C-like languages do allow this. But the C# language
designers decided that the programming practice of redeclaring variables in
such a way was error prone, and specifically outlawed it.
A similar spirit is seen in the switch / case statement, where limits are
placed on how one case statement can "fall through" to the next case
statement. Accidental case fall through is a somewhat common error in
C-like languages, and the language C# language designers want to "protect"
programmers somewhat.
--Don
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Peyman" <pe*****@netscape.net> wrote in message
news:69**************************@posting.google.c om...
Hi,
your problem is that the c# compiler does not like two variables with
the same name in the scope of the same function (here the myClassVar
variable in your main function) the static variable is also valid in
the same scope.
regards
peyman zehtab-fard
"Afzal Mazhar" <af***@mazhar.net> wrote in message
news:<fO**********************@news4.srv.hcvlny.cv .net>...
What is wrong with this?
class Example1
{
public static long myClassVar;
public static void Main()
{
{
long myClassVar = 5;
}
myClassVar = 36;
}
}
It will not compile.....why? I do not need a "fix" but rather am
confused why this will not compile.
It gives an error at myClassVar=36 that is conflicts with declaration
Example1.myClassVar
Thanks
Afzal