I do not get the following..I always thought I can access private fields only from class which the field was declared in. However in this case I am able to access it:
class Session
{
List<client> ListOfClients = new List<client>();
public void IterateClients(Action<client> action)
{
}
}
class client
{
private int A;
Session area;
public void SendData()
{
area.IterateClients(delegate(client c)
{
c.A = 5; //how come this is accessible?
});
}
}
You can only access private data from the CLASS it is a member of. Two objects of the same class can access each other's private parts.
Legal:
class c1
{
private int A;
public void test(c1 c)
{
c.A = 5;
}
}
Illegal:
class c2
{
public void test(c1 c)
{
c.A = 5;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With