Why doesn’t IList support AddRange

Because an interface shoud be easy to implement and not contain “everything but the kitchen”. If you add AddRange you should then add InsertRange and RemoveRange (for symmetry). A better question would be why there aren’t extension methods for the IList<T> interface similar to the IEnumerable<T> interface. (extension methods for in-place Sort, BinarySearch, … would … Read more

DataGridView Using SortableBindingList

Try this SortableBindingList: public class SortableBindingList<T> : BindingList<T> { private bool isSortedValue; ListSortDirection sortDirectionValue; PropertyDescriptor sortPropertyValue; public SortableBindingList() { } public SortableBindingList(IList<T> list) { foreach (object o in list) { this.Add((T)o); } } protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction) { Type interfaceType = prop.PropertyType.GetInterface(“IComparable”); if (interfaceType == null && prop.PropertyType.IsValueType) { Type underlyingType = … Read more

Why array implements IList?

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