0

When i make a nested class and name it B and make a variable called B, and when i try to work with it with a "this." then there stand its Ambiguous.

Shouldn't it be a bug since whenever you write "this." its obviously a variable you are trying to work with and not the class.

When i put the B class outside the A class, then it works, so i cant really see the reason why the c# creators would make it ambiguous just because its nested.

enter image description here

1
  • 1
    You can access any member that is part of the class with this. Members include variables but also methods, events and nested classes. Commented Nov 24, 2014 at 22:04

1 Answer 1

7

You cannot have a nested type and a member with the same name at all.
Even if you don't use B anywhere, your code will not compile.

Types and members within a class share the naming scope, and thus cannot share names.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.