If your collection type is a List<stuff>
, then the best approach is probably the following:
prods.RemoveAll(s => s.ID == 1)
This only does one pass (iteration) over the list, so should be more efficient than other methods.
If your type is more generically an ICollection<T>
, it might help to write a short extension method if you care about performance. If not, then you'd probably get away with using LINQ (calling Where
or Single
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…