Using the this Object Reference : This « Class Interface « C# / C Sharp






Using the this Object Reference

 

public class Product {

    public int yearBuilt;

    public void SetYearBuilt(int yearBuilt) {
        this.yearBuilt = yearBuilt;
    }
}
class MainClass{

    public static void Main() {
        Product myProduct = new Product();

        myProduct.SetYearBuilt(2000);
        System.Console.WriteLine("myProduct.yearBuilt = " + myProduct.yearBuilt);
    }
}

 








Related examples in the same category

1.Illustrates the use of the this object referenceIllustrates the use of the this object reference
2.Demonstrates using the this intrinsic variable, which allows a class instance to identify itselfDemonstrates using the this intrinsic variable, which allows a class instance to identify itself