Structs & Properties : Demonstrates creating properties for Structs, and getter / setter accessor usage for private and public members.
//datetime is a struct
//Creating a copy does not effect the original
//The memory is kept separate.
class Program {
static void Main()
{
//Initialize to 0
//New struct
S st = new S();
//Adding a property 'X', equal to 5.
st.X = 5;
Console.WriteLine(st.X);
}
//The struct's definition
struct S
{
//private member _x
int _x;
//public member 'X'. i.e., commonly with properties you
//have a private member, underscored "_apple", and then
//its public reflecion "Apple"
//The public member has getter/setter
public int X
{
//Its get returns the private counterpart...
get { return _x; }
//Its set sets the private counterpart...
set
{
if (value < 10)
{
_x = value;
}
}
}
};
// Define other methods and classes here
}