Add to an ICollection

List<Object> list = new List<Object>();
list.Add(object1);
list.Add(object2);
// etc...

ICollection collection = list;
// further processing of collection here.

Contrary to some comments, IList<T> does implement ICollection, at least as far as I can tell.


ICollection is an interface, you can't instantiate it directly. You'll need to instantiate a class that implements ICollection; for example, List<T>. Also, the ICollection interface doesn't have an Add method -- you'll need something that implements IList or IList<T> for that.

Example:

List<object> icollection = new List<object>();
icollection.Add("your item here");

Tags:

C#

Icollection