【发布时间】:2009-12-12 08:28:01
【问题描述】:
我有一个类,它只是一个列表的包装器,即,
public class Wrapper
{
public List<int> TList
{get;set;}
public Wrapper()
{
TList=new List<int>();
}
}
我想让Wrapper 继承自 IEnumerable 以便我可以使用以下语法:
Wrapper wrapper = new Wrapper()
{
2,4,3,6
};
知道如何实现IEnumerable<T>或IEnumerable的接口,以及如何定义方法体吗?
【问题讨论】:
-
不,使用 IEnumerable
将无法正常工作。我认为你必须实现 ICollection . -
不,deerchao,它需要IEnumerable
。我们不要求 ICollection ,当然,这样做是明智的。
标签: c# ienumerable