Version 1  
Vehicle1 Example
- Properties are implemented using global variables.
- A default constructor is supplied if no constructors are
defined in the class. It performs these initializations:
Datatype | Initial Value |
Any numeric type | 0 |
Char | '\0' |
Boolean | false |
DateTime | 1/1/1 12:00:00 AM |
Any reference type | null |
- For reference type objects, the assignment operator =
in the statement
y = x;
makes both x and y refer to the same object.
- To compare the addresses in reference variables, use the
ReferenceEquals operator, not the == operator:
if (object.ReferenceEquals(x, y))
Console.WriteLine("x and y are the same object.")
 
Version 2  
Vehicle2 Example
- Properties can be implemented using Java-style accessor methods
(getters) and mutator methods (setters).
 
Version 3  
Vehicle3 Example
- Preferred implementation: use C# properties with get and get parts.
public int Age
{
get { return mvarAge; }
set { mvarAge = value; }
}
- Use .Net properties to participate fully in the .Net
machinery.
- The get and set parts can have
different accessibilities.
public int Age
{
get { return mvarAge; }
private set { mvarAge = value; }
}
 
Version 4  
C#-1.Structure and Vehicle4 Examples
- Small objects with few properties can be more
efficiently implemented as a value type structure instead of a reference type object.
- Structures can have instance variables, constructors,
methods and properties.
- No user defined constructor with empty signature is allowed.
- Structures cannot participate in inheritance.
- For value type objects,
y = x; copies the data from x
into y. x and y remain distinct value type objects.