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); } }
1. | Illustrates the use of the this object reference | ||
2. | Demonstrates using the this intrinsic variable, which allows a class instance to identify itself |