Invoking Base Class Constructor [Resolved]
I'm very new to C# and have a quick question...
When a class is derived from a base class, is the base class constructor always invoked when an instance of the derived class is created, regardless of whether ": base()" is added to the derived class constructor?
e.g I have a "Control" class, and a "Listbox" class which dervies from it.
When I create an instance of "Listbox", is the "Control" constructor always invoked?
Thanks...
Re: Invoking Base Class Constructor
It calls the default constructor automaticaly. If you need to call an other constructor, then you have to do it manualy. A test like this reveals it.
Code:
using System;
namespace testbase{
class Class1{
static void Main(string[] args){
Class2 test1 = new Class2();
Class3 test2 = new Class3();
Class2 test3 = new Class3();
Console.WriteLine("test1: " + test1.hello);
Console.WriteLine("test2: " + test2.hello);
Console.WriteLine("test3: " + test3.hello);
Console.ReadLine();
}
}
class Class2{
public string hello;
public Class2(){
hello = "hello";
}
}
class Class3 : Class2{
public Class3(){
}
}
}
- ØØ -
Re: Invoking Base Class Constructor
Re: Invoking Base Class Constructor [Resolved]
No, problem, just happy to help out.
- ØØ -