Sorting an IList in C#
You can use LINQ: using System.Linq; IList<Foo> list = new List<Foo>(); IEnumerable<Foo> sortedEnum = list.OrderBy(f=>f.Bar); IList<Foo> sortedList = sortedEnum.ToList();
You can use LINQ: using System.Linq; IList<Foo> list = new List<Foo>(); IEnumerable<Foo> sortedEnum = list.OrderBy(f=>f.Bar); IList<Foo> sortedList = sortedEnum.ToList();
IEnumerable<T> represents a series of items that you can iterate over (using foreach, for example), whereas IList<T> is a collection that you can add to or remove from. Typically you’ll want to be able to modify an Order by adding or removing OrderLines to it, so you probably want Order.Lines to be an IList<OrderLine>. Having … Read more
Because an array allows fast access by index, and IList/IList<T> are the only collection interfaces that support this. So perhaps your real question is “Why is there no interface for constant collections with indexers?” And to that I have no answer. There are no readonly interfaces for collections either. And I’m missing those even more … Read more