To declare a class instance, include the class name, followed by an identifier of the particular instance of the class. In addition, you must use the new keyword, followed by calling a constructor for the object.
When a class is instantiated, memory is reserved for those objects members on the managed heap.
The following is an example of declaring class instances.
using System;
namespace Client.Chapter_5___Building_Your_Own_Classes
{
class DeclaringClassInstances
{
static void Main(string[] args)
{
//Creates an instance of a class
ClassInstantiated MyClass = new ClassInstantiated();
}
}
public class ClassInstantiated
{
public void Display()
{
Console.WriteLine("Hello World");
}
}
}