Can You Add to Ienumerable

IEnumerable is an interface. You can’t use Add() on an IEnumerable because they’re not required to implement an Add() method. See the IEnumerable documentation on MSDN. Instead, create a generic list which inherits from the interface IList.

Which is better IEnumerable or list?

In terms of performance, the answer is it depends. If you need the results to be evaluated at once (say, you’re mutating the structures you’re querying later on, or if you don’t want the iteration over the IEnumerable<T> to take a long time) use a list.

What is the difference between ICollection and IEnumerable?

An IEnumerable is a list or a container which can hold some items. You can iterate through each element in the IEnumerable. … ICollection is another type of collection, which derives from IEnumerable and extends it’s functionality to add, remove, update element in the list.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest