Why does it not generate an error?
If i try change private field of this struct in main program file – it generates an error, but not in struct implementation.
public struct MyStruct
{
private int privateField;
public int MyField
{
get { return privateField; }
set { if (value >= 0) privateField = value; else value = 0 }
}
public void SomeMethod (MyStyruct s)
{
s.privateField = 10; // no error here.
}
}
Private members are restricted to the class or struct not the object. In this case, even though
sis a different object fromthis, it still works.