Cast IList to List
Try List<SubProduct> subProducts = new List<SubProduct>(Model.subproduct); or List<SubProduct> subProducts = Model.subproducts as List<SubProduct>;
Try List<SubProduct> subProducts = new List<SubProduct>(Model.subproduct); or List<SubProduct> subProducts = Model.subproducts as List<SubProduct>;
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
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
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