Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以方法作为参数调用基构造函数_C#_.net - Fatal编程技术网

C# 以方法作为参数调用基构造函数

C# 以方法作为参数调用基构造函数,c#,.net,C#,.net,我是C#的初学者,不知道如何从子类中调用基构造函数: 基类: public class LookupScript { protected Func<IEnumerable> getItems; protected LookupScript() { // } public LookupScript(Func<IEnumerable> getItems) : this() { Check.No

我是C#的初学者,不知道如何从子类中调用基构造函数:

基类:

public class LookupScript
{
    protected Func<IEnumerable> getItems;

    protected LookupScript()
    {
        //
    }

    public LookupScript(Func<IEnumerable> getItems) : this()
    {
        Check.NotNull(getItems, "getItems");
        this.getItems = getItems;
    }
公共类LookupScript
{
受保护的功能获取项目;
受保护的LookupScript()
{
//
}
public LookupScript(Func getItems):this()
{
Check.NotNull(getItems,“getItems”);
this.getItems=getItems;
}
我的派生类:

public class PresenceLookup : LookupScript
{
    public PresenceLookup() :base(??)
    {
     //
    }
    List<string> myMethod()
    {
        return null;
    }
public类PresenceLookup:LookupScript
{
public PresenceLookup():基(??)
{
//
}
列表myMethod()
{
返回null;
}
如何将
myMethod
传递给基类


谢谢

您不能,因为
myMethod
是一个实例方法,并且您不能访问与构造函数初始值设定项中创建的实例有关的任何内容。不过,这可以:

public class PresenceLookup : LookupScript
{
    public PresenceLookup() : base(MyMethod)
    {
    }

    private static List<string> MyMethod()
    {
        return null;
    }
}

另一方面,值得提出一个问题-在这里,
lookupParams
没有被声明,并且似乎是不相关的,同上
Check.NotNull
,并且无参数构造函数是不相关的。一个完全由参数化构造函数组成的类会更好。
public class PresenceLookup : LookupScript
{
    public PresenceLookup() : base(() => null)
    {
    }
}