Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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#模板IEnumerable的模板方法<;T>;。可能吗?_C#_Templates_C# 3.0 - Fatal编程技术网

C#模板IEnumerable的模板方法<;T>;。可能吗?

C#模板IEnumerable的模板方法<;T>;。可能吗?,c#,templates,c#-3.0,C#,Templates,C# 3.0,有人能帮我解决这个问题吗 我有一个基本类: public class BaseShowFilter { public int TotalCount { get; set; } public int FromNo { get; set; } public int ShowCount { get; set; } public string SortFieldName { get; set; } public bool SortAsc

有人能帮我解决这个问题吗

我有一个基本类:

public class BaseShowFilter {
    public int    TotalCount { get; set; }  
    public int    FromNo { get; set; }
    public int    ShowCount { get; set; }
    public string SortFieldName { get; set; }
    public bool   SortAsc { get; set; }
}
还有几个基类中的子类。然后我有一些其他类存储在中(例如)

所以我需要在BaseShowFilter中实现一个函数,该函数将在参数IEnumerable中接受,并返回IEnumerable

我怎么写呢?在纯C++中,它将简单地作为1,2,3…但在这里我不知道该怎么做。结果可能是这样的:

public class BaseShowFilter {
    public int    TotalCount { get; set; }  
    public int    FromNo { get; set; }
    public int    ShowCount { get; set; }
    public string SortFieldName { get; set; }
    public bool   SortAsc { get; set; }

    public T FilterList<T>(T SrcList) where T :IEnumerable<> {
        return srcList.Skip(this.FromNo-1).Take(this.ShowCount);
    }
}
公共类BaseShowFilter{
公共整数TotalCount{get;set;}
public int FromNo{get;set;}
公共int ShowCount{get;set;}
公共字符串SortFieldName{get;set;}
公共布尔排序{get;set;}
公共T过滤器列表(T SrcList),其中T:IEnumerable{
返回srcList.Skip(this.FromNo-1).Take(this.ShowCount);
}
}

这是通常的方法:

public IEnumerable<T> FilterList<T>(IEnumerable<T> source)
{
    return source.Skip(this.FromNo - 1).Take(this.ShowCount);
}
public IEnumerable过滤器列表(IEnumerable源代码)
{
返回source.Skip(this.FromNo-1).Take(this.ShowCount);
}
public class BaseShowFilter {
    public int    TotalCount { get; set; }  
    public int    FromNo { get; set; }
    public int    ShowCount { get; set; }
    public string SortFieldName { get; set; }
    public bool   SortAsc { get; set; }

    public T FilterList<T>(T SrcList) where T :IEnumerable<> {
        return srcList.Skip(this.FromNo-1).Take(this.ShowCount);
    }
}
public IEnumerable<T> FilterList<T>(IEnumerable<T> source)
{
    return source.Skip(this.FromNo - 1).Take(this.ShowCount);
}