我有一些基于IEnumerable<T>
的自定义列表。现在我想重载构造函数,并用我得到的初始列表做一些自定义的东西。IEnumerable构造函数过载
//Constructor
public CustomList(IEnumerable<T> collection) : base(collection)
{
//do some stuff with the collection e.g. iterate
foreach(T obj in collection)
{
//do some stuff with obj
}
}
它甚至有可能这样做吗?因为IEnumerable只能在base(collection)
处枚举一次,但我猜,循环会失败。
编辑: ,因为它并不完全清楚给大家:我的基类是IEnumerable<T>
和IEnumerable
只能在我的情况下,一旦枚举。
你的基础课程是什么? – 2013-03-22 19:40:56
你真的尝试过吗?我看到你在这里没有问题。我不知道是什么让你觉得'IEnumerable只能枚举一次'。 – 2013-03-22 19:42:48
@MattBurland - 对于一些藏品来说也是如此。 – Oded 2013-03-22 19:43:24