How to create a constructor in the descendant with parameters that do not match the parameters of the base constructor

There is a constructor in the base class

public Kons(int a, string b){}

You need to make a constructor in the heir

public Nasl(int a, int[] c):base(a,b){}

Writes that the non-static field b requires a reference to the object. You can't make b static. What to do?

Author: Алефпатий, 2020-01-12

1 answers

You can add a third parameter b to the descendant constructor, which has a default value:

public BaseConstructor (int a, string b) 
{
...
}
public NaslConstructor (int a, int[] c, string b = "defaultString")
: base (a, b)
{
...
}

Or if this string is the same for the heir, then you can use a constant string:

public BaseConstructor (int a, string b) 
{
...
}
public NaslConstructor (int a, int[] c)
: base (a, "constString")
{
...
}
 2
Author: Oleg Klezovich, 2020-01-12 10:03:48