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?
});
}
}
Technically it’s not
Sessionclass that’s accessing privateAvariable, it’s delegate function created inSendData()that does this. There is no problem with that. Think of it asIterateClientsis just calling method fromclientclass, which method can accessAvariable since it is on the same class.