- The new operator dynamically allocates memory for an object and returns a reference to it.
- This reference is, more or less, the address in memory of the object allocated by new.
- This reference is then stored in a variable.
public class House
{
public string make;
public string model;
public string color;
public int yearBuilt;
public void Start()
{
System.Console.WriteLine(model + " started");
}
public void Stop()
{
System.Console.WriteLine(model + " stopped");
}
}
class MainClass
{
public static void Main()
{
House myHouse;
System.Console.WriteLine("Creating a House object and assigning its memory location to myHouse");
myHouse = new House();
}
}
Creating a House object and assigning its memory location to myHouse