guys,thanks for your time. As we known,the key words 'Private' and 'Protected' are very useful to keep some methods,fields,properties from invalid accessing outside the class.But I had got a problem in a specific circumstance.Here is the example:
Class Node
{
public string Name {get; private set;}//Private setting authority
public int ID {get;set}
public Node Previous {get;set;}
public Node Next {get;set;}
public void Test()
{
this.Name='Valid';
this.Next.Name='Invalid';//Is this valid??
}
}
Just like the code above,we got a 'Node' Class here with two properties named 'Previous' and 'Next' which are also 'Node' type.Now let's focus on the 'Test()' method.It's valid to Set 'this.Name',but is that weird to set 'this.Next.Name'?Unfortunately,the complier treats this as a valid format!
So far as I was taught,'Private' means it can not be used outside the class.But in this situation,I can access to any non-public members( private/protected etc..) of 'Previous' and 'Next'.
This really confuses me a lot,would u plz give some advices,thanks!