How to: Why are private fields private to the type, not the instance?
How to: Why are private fields private to the type, not the instance?
Why are private fields private to the type, not the instance?
In C# (and many other languages) it’s perfectly legitimate to access private fields of other instances of the same type. For example:
public class Foo { private bool aBool; public void DoBar(Foo anotherFoo) { if(anotherFoo.aBool) ... } }
As the C# specification(sections 3.5.1, 3.5.2) states access to private fields is on a type, not…
View On WordPress









