A class declaration acts like a template or blueprint. You can create any number of class instances from it.
Instance Members: Every instance of a class is a separate entity with its own set of data members, isolated from other instances of the same class. These are known as instance members because they belong to individual class objects.
Static Members: Instance members are the default. You may also declare static members, which belong to the class itself rather than any instance. We will cover this in later lessons.
Let’s look at an example
class Program
{
static void Main(string[] args)
{
Factory factoryFox = new Factory();
Robot robot1 = new Robot();
Robot robot2 = new Robot();
Robot robot3 = new Robot();
}
}
class Factory
{
}
class Robot
{
public string name;
public void SayHello()
{
Console.WriteLine($"Hello everyone my name is {name},I come from Foxdevelop.com");
}
}Code language: C# (cs)
In this sample, there are two classes: Factory and Robot. The Robot class contains one method and one field called name. Factory has no name field.
The main method creates one Factory instance and three Robot instances.
Let’s examine how data is arranged in memory.

The three robots robot1, robot2 and robot3 each hold their own independent name value stored at separate memory locations with no cross-interference. Modifying robot1 will not affect robot2.
static void Main(string[] args)
{
Factory factoryFox = new Factory();
Robot robot1 = new Robot();
Robot robot2 = new Robot();
Robot robot3 = new Robot();
robot1.name = "Tom"; // Each name is independent and separated
robot2.name = "Jack";
robot3.name = "Smith";
}Code language: C# (cs)
Only One Copy of Function Members
As shown above, every instance maintains its own separate name. Changing the name of one instance does not alter the name stored inside another. Besides fields, classes also contain function members.
Is there only a single copy of each function member shared across all instances?
The actual code body of a function (method): exists once globally and shared by all instances
After compilation, the machine instructions for methods reside within the Method Table, which belongs to the type itself. All heap instances of that class share this single set of instructions; each object does not receive its own duplicate copy of the function.
Take SayHello inside the Robot class as an example
class Robot
{
public string name;
public void SayHello()
{
Console.WriteLine($"Hello everyone my name is {name},I come from Foxdevelop.com");
}
}Code language: C# (cs)
Memory layout includes more regions besides heap and stack. Method implementations, for instance, are stored inside the Method Table.
Class functions are stored inside the method table. When invoked, execution targets this shared method table entry.
static void Main(string[] args)
{
Factory factoryFox = new Factory();
Robot robot1 = new Robot();
Robot robot2 = new Robot();
Robot robot3 = new Robot();
robot1.name = "Tom";
robot2.name = "Jack";
robot3.name = "Smith";
robot1.SayHello();
robot2.SayHello();
robot3.SayHello();
}Code language: C# (cs)
In the snippet above, all three SayHello calls target the exact same function. Local variables inside the method remain separate, and field access within the method depends on which instance triggers the call.
public void SayHello()
{
Console.WriteLine($"Hello everyone my name is {name},I come from Foxdevelop.com");
}Code language: C# (cs)
When robot1 executes SayHello, name resolves to Tom. When robot2 executes SayHello, name resolves to Jack, and so on.
Instance Members