Using Initializers : Class Definition : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Class Definition »

 

Using Initializers








    
 


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);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Class Definition