Skip to content

Instantly share code, notes, and snippets.

@GavinOsborn
Created October 8, 2013 23:26
Show Gist options
  • Select an option

  • Save GavinOsborn/6893559 to your computer and use it in GitHub Desktop.

Select an option

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?
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