I have 2 scenarios.
This fails:
class F<X>
{
public X X { get; set; }
}
error CS0102: The type 'F<X>
' already contains a definition for 'X
'
This works:
class F<X>
{
class G
{
public X X { get; set; }
}
}
The only logical explanation is that in the second snippet the type parameter X is out of scope, which is not true...
Why should a type parameter affect my definitions in a type?
IMO, for consistency, either both should work or neither should work.
Any other ideas?
PS: I call it 'lexical', but it is probably not the correct term.
Update:
As per Henk's answer, here is a non-generic version displaying the same behavior, but perhaps easier to grok.
Fails:
class F
{
class X { }
public X X { get; set; }
}
Works:
class X { }
class F
{
public X X { get; set; }
}
From what I can see, the C# compiler creates a lexical scope at type definition boundries.
It also implies that types and member names live in the same 'location' (or namespace
in terms of LISP).