public class Remover
{
public void Remove
{
collection.Remove(item);
}
}
So what would you expect this function to do:
public void TryToRemove()
{
int[] ints = new[] { 3, 4, 5, 6, 7 };
Remover remover = new Remover();
remover.Remove(ints, 3);
}
Maybe it does nothing, the collection isn't really readonly so the return call should probably return false. Maybe it throws an exception, but, and here is the crux of my point, I would expect some kind of warning to displayed if that was the case.
Indeed, it does throw an exception: "Test method CollectionExample.UnitTest1.TryToRemove threw exception: System.NotSupportedException: Collection was of a fixed size.."
(The .. is verbatim from the error message)
I compiled with warnings as errors and used Style Cop and Code Analysis, you'd think one of those tools would give you a warning that this implicit cast you are doing is going to cause you problems. Or how about this Microsoft, why even make an array inherit from, or have an implicit cast to ICollection if you are just going to provide a degenerate implementation. Just having it implement IEnumerable seems like it would have been a better choice.
That's my end rant, just one more thing to keep in mind when pushing the bits around.
0 comments:
Post a Comment