Jamie Dixon Jamie Dixon - 9 months ago 67
C# Question

What happens when casting IEnumerable to ICollection

Given a case such that:

var collection = myEnumerable as ICollection<MyType>;

What happens under the hood?
has a count property. Does this casting enumerate the enumerable to get the count or does something more involved happen?


Nothing happens. If myEnumerable indeed is an ICollection<MyType> collection will contain it. Otherwise it will be null. Simple as that.