Based on some requirements, I want to add all constructors/methods of the base class into the derived class without writing methods/constructors in the derived class.
For that I have written code as shown below but it does not work. It shows error "ConsoleApplication1.TestClass2' does not contain a constructor that takes 1 arguments".
How can I fix that?
I cannot create any method or constructor in the base class. Is there any other way apart from inheriting a class?
My code:
namespace ConsoleApplication1
{
public class TestClass1
{
public TestClass1()
{
Console.WriteLine("This is base class constructor1");
}
public TestClass1(string str1,string str2)
{
Console.WriteLine("This is base class constructor2");
}
public TestClass1(string str1,string str2,string str3)
{
Console.WriteLine("This is base class constructor3");
}
public TestClass1(string str1,string str2,string str3,string str4)
{
Console.WriteLine("This is base class constructor4");
}
}
public class TestClass2 : TestClass1
{
}
class Program
{
static void Main(string[] args)
{
TestClass2 test = new TestClass2("test");
TestClass2 test1 = new TestClass2("test,test");
}
}
}