I have a class that’s IEnumerable<T> where I want to have different properties that provides a filtered IEnumerable<T> access.
So for instance:
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;
}
}
}
Is this how it should be? Just not sure, about it completely.
Thanks.
Sure, but you might want to rewrite it as
which does the exact same thing.