G
Guest
Hello,
Lets say I have this class definition:
public class Class1
{
private int _privInt = 2;
protected int _protInt = 4;
public void SomeMethod(Class1 class1_)
{
System.Diagnostics.Debug.WriteLine(class1_._privInt);
System.Diagnostics.Debug.WriteLine(class1_._protInt);
}
}
I have defined a private int field and a protected int field. Since those
fields have restricted access, how come I can access them in SomeMethod
without any issues? I would think that since _privInt is private to the
Class1 class, specifically the method parameter class1_, I wouldn't be able
to access it.
Can any private field of a class be readily accessed from within the
definition of that class, regardless of which instance of the class you are
using?
Thanks.
Lets say I have this class definition:
public class Class1
{
private int _privInt = 2;
protected int _protInt = 4;
public void SomeMethod(Class1 class1_)
{
System.Diagnostics.Debug.WriteLine(class1_._privInt);
System.Diagnostics.Debug.WriteLine(class1_._protInt);
}
}
I have defined a private int field and a protected int field. Since those
fields have restricted access, how come I can access them in SomeMethod
without any issues? I would think that since _privInt is private to the
Class1 class, specifically the method parameter class1_, I wouldn't be able
to access it.
Can any private field of a class be readily accessed from within the
definition of that class, regardless of which instance of the class you are
using?
Thanks.