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) { }
}
Was it helpful?

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)
    {
    }
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top