Suppose I have an ICollection<SomeClass>
.
I have the following two variables:
SomeClass old;
SomeClass new;
How can I achieve something like the following using an ICollection<SomeClass>
?
// old is guaranteed to be inside collection
collection.Replace(old, new);
Do that:
There is no black magic here:
ICollection<T>
is not ordered and only providesAdd
/Remove
methods. Your only solution would be to check if the actual implementation is something more, such asIList<T>
:The
ICollection<T>
interface is quite limited, you will have to useRemove()
andAdd()