I have a base class, which is as follows:
public Data()
{
id = num++;
SetVariables();
}
//fill every Variable varNames, parseInduction, noise, seperator in Children Classes
public Data(String line)
{
//first declare all variables in sub classes
if (id == 0)
throw new NotSupportedException("You are not allowed to use this constructor for creating the first instance!");
id = num++;
SetVariables();
parseLine(line);
}
And i also have a Sub Class extending this Class.
class DienstGruppe : Data
{
protected override void SetVariables(){
varNames = new String[] {"id", "name"};
parseInduction = "DienstGruppen = {";
parseEnd = "};";
beginOfDataLine = "<";
endOfDataLine = ">";
noise = new String[] { "\"" };
}
}
And i try to create an object with the Activator.CreateInstance() Function as follows:
Data myData = (Data)Activator.CreateInstance(this.GetType(), new object[] { line });
Note: this.GetType() is used in a function of Data by the extending class, to get the Type of the current class.
But this causes a problem. Bizzarly i get an error, that the class (in my case DienstGruppe) does not have the constructor. I guess inheritance is not the same in c# as in java. So how can i solve this problem?
It works for "Data" though.
Regards, Dominik
line
? You must make sure the argument list and types match. – Unscreened