ilist

IList vs IEnumerable for Collections on Entities

廉价感情. 提交于 2019-11-26 19:23:14
When I have entities in my domain with lists of things, should they be exposed as ILists or IEnumerables? E.g. Order has a bunch of OrderLines. Matt Hamilton 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 said that, there are some framework design decisions you should make. For example, should it be possible to add

DataGridView Using SortableBindingList

穿精又带淫゛_ 提交于 2019-11-26 11:30:06
问题 I have a function that returns an IList< T > and is the DataSource for a DataGridView. I learned that DataGridView won\'t sort IList. I read This stackoverflow Q&A and am trying to implement SortableBindingList. I must be doing something wrong because my DataGridView is empty. I also tried to access an element from the SortableBindingSource with a TextBox and nothing as well. using Microsoft.SqlServer.Management.Controls; public partial class Form1 : Form { IBusinessLayer businessLayer; IList

Why array implements IList?

只愿长相守 提交于 2019-11-26 10:28:42
See the definition of System.Array class public abstract class Array : IList, ... Theoretically, I should be able to write this bit and be happy int[] list = new int[] {}; IList iList = (IList)list; I also should be able to call any method from the iList ilist.Add(1); //exception here My question is not why I get an exception, but rather why Array implements IList ? Because an array allows fast access by index, and IList / IList<T> is 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

IList vs IEnumerable for Collections on Entities

≯℡__Kan透↙ 提交于 2019-11-26 06:57:58
问题 When I have entities in my domain with lists of things, should they be exposed as ILists or IEnumerables? E.g. Order has a bunch of OrderLines. 回答1: 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 said that, there

Why array implements IList?

[亡魂溺海] 提交于 2019-11-26 02:09:33
问题 See the definition of System.Array class public abstract class Array : IList, ... Theoretically, I should be able to write this bit and be happy int[] list = new int[] {}; IList iList = (IList)list; I also should be able to call any method from the iList ilist.Add(1); //exception here My question is not why I get an exception, but rather why Array implements IList ? 回答1: Because an array allows fast access by index, and IList / IList<T> is are the only collection interfaces that support this.