What is the best way to get a value from a ICollection? We know the Collection is empty apart from that.
Without generics and because ICollection
implements IEnumerable
you can do like in example 1. With generics you simple need to do like example 2:
List l = new List();
l.Add("astring");
ICollection col1 = (ICollection)l;
ICollection col2 = (ICollection)l;
//example 1
IEnumerator e1 = col1.GetEnumerator();
if (e1.MoveNext())
Console.WriteLine(e1.Current);
//example 2
if (col2.Count != 0)
Console.WriteLine(col2.Single());