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