I\'m making my constructors a bit more strict by removing some of my empty constructors. I\'m pretty new to inheritance, and was perplexed with the error that I got: Base Class
It has to call some constructor. The default is a call to base()
.
You can also use static methods, literals, and any parameters to the current constructor in calls to base()
.
public static class MyStaticClass
{
public static int DoIntWork(string i)
{
//for example only
return 0;
}
}
public class A
{
public A(int i)
{
}
}
public class B : A
{
public B(string x) : base(MyStaticClass.DoIntWork(x))
{
}
}