Jon,

I don't think it's that the program itself breaks any rules, rather that the
syntax clashes with C#'s name-resolution specs.  Within your method:

void Method()
{
decl++;
}

'decl' is really 'this.decl', or 'T.decl' - it's only the ability of the
compiler to resolve the full name that allows you to omit the identifier.

The key, I think, is that the compiler *assumes* you will use the new
variable you have just declared.  In which case, your reference to
'this.decl' *without* the 'this' identifier would make any use of the new
'decl' impossible.

Jim

> -----Original Message-----
> From: Jon Jagger [mailto:[EMAIL PROTECTED]]
> Sent: 17 May 2002 19:03
> To: [EMAIL PROTECTED]
> Subject: Re: [DOTNET] Is this program conforming?
>
>
> On Fri, 17 May 2002 09:24:48 -0700, Jim Arnold
> <[EMAIL PROTECTED]>
> wrote:
>
> >Ah, then how about Section 10.3, paragraph 3, items 18 and 19?
> >
> >18 The local variable declaration space of a block includes
> any nested
> >blocks.
> >19 Thus, within a nested block it is not possible to declare a local
> >variable with the same name as a local variable in an
> enclosing block.
>
> Yeah at first I thought that would be it too. But on closer
> inspection the
> outer declaration is not in a block and its not a local variable
> declaration either - its a field declaration.
>
> If you remove the _use_ from the fragment then it compiles ok (as 10.7
> para 1 sentence 1 says it should).
>
> class T
> {
>     int decl; // of a field
>
>     void Method()
>     {
>         // decl++;
>
>         {
>             int decl; // of a local variable
>         }
>     }
> }
>
> It's the appearance of decl as a simple-name in an expression
> that seems
> to cause the compiler error.
>
> Cheers
> JJ
>
> You can read messages from the DOTNET archive, unsubscribe
> from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to