Creating an instance is the way that you can actually use the class: it is like buying a car.
Until you buy a car, you can't drive it when you want: with a class, until you create an instance you can't use it's properties and methods.
MyClass mc = new MyClass();
Creates an instance of MyClass which you can now access via the variable
mc
- which is a reference to the actual instance. That sounds a little confusing (and without picture it is) but think of tit this way:
mc
is not the actual MyClass instance itself, it just tells the system where to find it - you can change MyClass without affecting the instance:
MyClass mc;
mc
exists, but it is null - it has no instance associated with it, and any attempt to use mc will cause an "Object reference not set to an instance of an object" error.
mc = new MyClass();
Creates an instance of MyClass, and assigns it to
mc
- you can now access the properties of the class instance:
mc.Text = "My first instance";
Console.WriteLine(ms.Text);
You can also create other variables, and other instances:
MyClass mc2 = new MyClass();
mc2.Text = "My second instance";
Console.WriteLine(mc);
Console.WriteLine(mc2);
Will write
My first instance
My second instance
You can copy
mc
MyClass mc3 = mc;
Console.WriteLine(mc);
Console.WriteLine(mc2);
Console.WriteLine(mc3);
Will write
My first instance
My second instance
My first instance
You can change
mc
mc = new MyClass();
mc.Text = "My third instance";
Console.WriteLine(mc);
Console.WriteLine(mc2);
Console.WriteLine(mc3);
Will write
My third instance
My second instance
My first instance
There is more too it, but that should give you enough for the moment!
Inheritance is different: it doesn't create anything you code can use without an instance of the new class being created - what it does do is allow the new class to have all the properties and methods of the inherited class without having to write them all again.
If you like, the make of a car (Ford, BMW, etc.) is an inherited class from Car, because the all have four wheels, an engine, a steering wheel, and so forth. The Ford class adds an oval badge, the BWM class adds a round badge and so forth. If you can Drive a Car, you can Drive a Ford, and a BMW, and all the other makes which are derived from Car.