Using Initializers

image_pdfimage_print
   
 


public class Product {
    public string make = "Ford";
    public string model = "T";
    public string color;  // default value of null
    public int yearBuilt = 1910;

    public void Start() {
        System.Console.WriteLine(model + " started");
    }

    public void Stop() {
        System.Console.WriteLine(model + " stopped");
    }
}

class MainClass {

    public static void Main() {
        Product myProduct = new Product();
        System.Console.WriteLine("myProduct.make = " + myProduct.make);
        System.Console.WriteLine("myProduct.model = " + myProduct.model);
        if (myProduct.color == null) {
            System.Console.WriteLine("myProduct.color is null");
        }
        System.Console.WriteLine("myProduct.yearBuilt = " + myProduct.yearBuilt);
    }
}