简体   繁体   English

C#:当用作论坛的参数时,“所有者”是什么意思?

[英]C#: What does 'owner' mean when used as argument of a class?

In the class below what does the "owner" argument do to both myClass and the base class? 在下面的类中,“owner”参数对myClass和基类的作用是什么?

public class Base
{
    public myClass(owner) : base (owner) { }
}

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

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. 前面的示例演示了如何将构造函数参数传递给base类的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM