我有一个类是IEnumerable<T>
我想拥有不同的属性,提供过滤IEnumerable<T>
访问。是否有可能拥有一个属性为IEnumerable <T>?
因此,例如:
class Shape
ShapeType = Box/Sphere/Pyramid
class ShapeCollection : IEnumerable<Shape>
{
public IEnumerable<Shape> OnlyBox
{
foreach(var s in this)
{
if (s.ShapeType == Box)
yield return s;
}
}
}
这是应该如何?只是不确定,关于它完全。
谢谢。
+1表现力。 – Cumbayah 2010-09-02 18:58:30
谢谢,是的,这在我的脑海里有点片面。现在我可以清楚地看到它。 – 2010-09-02 19:01:56
WTG w/LINQ FTW。 – Randolpho 2010-09-02 21:20:52