Created
October 8, 2013 23:26
-
-
Save GavinOsborn/6893559 to your computer and use it in GitHub Desktop.
Did you know that in C# an instance of a Type can access the private members of another instance of the same type?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main() | |
| { | |
| var a = new Foo("Secret of A"); | |
| var b = new Foo("Secret of B"); | |
| a.SomeMethod(b); | |
| } | |
| public class Foo | |
| { | |
| private string _privateMember; | |
| public Foo(string secret) | |
| { | |
| _privateMember = secret; | |
| } | |
| public void SomeMethod(Foo anotherFoo) | |
| { | |
| Debug.WriteLine(anotherFoo._privateMember); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment