class TheData {
private int m_privIntValue; //data cell not visible/accessible outside of class/object
public int IntValue { // the property to access/manage the data cell
get {
return m_privIntValue;
}
set {
if ((-100 <> value)) //logic can be placed within a property method
m_privIntValue = value;
else
Console.WriteLine("Must be between -100 and 100!");
}
}
}
So, in my program, if I have instantiated an object from TheData:
TheData myData = new TheData();
I can simply make assignments:
myData.Intvalue = 11;
or use it like a value type:
int x = myData.IntValue;

No comments:
Post a Comment