Ok, how about a few constructors?
// a sample base class
class KBase {
public readonly int value; // making it readonly means it can only be assigned to once, and that has to happen during a constructor.
public KBase ( int startValue ) { value = startValue; }
}
class KHandler : KBase
{
public readonly string name = "wut";
// this is a parameterless constructor, whose implementation invokes another constructor ( the one below ) of this class
public KHandler () : this ( "huh" ) {
}
// this is a 1 parameter constructor, whose implementation ensures KBase is properly initialized, and then proceeds to initialize its part of the new instance.
public KHandler ( string val ) : base ( 3 ) {
name = val;
}
}
class Test {
static void Main()
{
// this next line calls the parameterless constructor I defined above
KHandler handler = new KHandler();
// and this next line calls the 1 parameter constructor
KHandler handler2 = new KHandler("something else");
Console.WriteLine("All Good 1"+handler.name);
Console.WriteLine("All Good 2"+handler2.name);
}
}
I think you want the basic mechanism of constructors, which are run in slightly special environment after the new class instance is allocated and "zeroed". The special environment is that the compiler/language ensure that all the base classes and fields are properly initialized, and, you're allowed to assign to readonly members (only) during construction.
Constructors can call base class constructors to get those bases properly initialized; constructors can also invoke another constructor of the same class before they proceed.
You can have more than one constructor per class -- like in my example above. If you don't specify a constructor, then the compiler effectively inserts a blank parameterless constructor for you. If you don't want this behavior, then adding your own constructor (of any parameter list) cancels the automatic creation of the blank parameterless constructor by the compiler/language. (If you added your own parameterized constructor and still want the parameterless constructor too, you have to add it back yourself.)
The first constructor (the parameterless one) is called as a result of the first new KHandler() and the second one is called by the second new KHandler (string).
Once constructed, an object is considered ready for use. Anyway, search on the general construct of constructors and you'll get more information.