C#: What does 'owner' mean when used as argument of a class?
Question
In the class below what does the "owner" argument do to both myClass and the base class?
public class Base
{
public myClass(owner) : base (owner) { }
}
La solution
If you have two classes, one is a base class the other a derived class, when you create constructor for the derived class, you can pass arguments to the base clas.
public class Base
{
private string Test = "";
public Base(string test)
{
Test = test;
}
}
public class Derived : Base
{
public Derived(string test) : base(test) // - This will call public Base(string test)
{
}
}
Autres conseils
The following would compile and seem to fit your scenario minus the fact that you're not using the verbatim identifier @
:
public class Base
{
public Base(myMethod owner)
{
}
}
public class @new : Base
{
public @new(myMethod owner) : base(owner)
{
}
}
The previous example demonstrates how to pass a constructor argument down to the base
class' implementation.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow