2013-12-18 66 views
1

代碼:如何將項目添加到ICollection中的特定索引中?

TestItem TI = new TestItem(); 
ITestItem IC = TI; 
controls.TestItems.Add(IC); //This adds the item into the last column, but I need to add this in a particular index 

TestItem is a Class 
ITestItem is an Interface 
controls is a local variable 
TestItems is a ICollection<ITestItem> 

如何將項目添加到ICollection的一個特定的指數?

回答

4

ICollection<T> does not have insert method它允許插入指定的索引位置。

相反,你可以使用IList<T>其中確實有插入方法:

void Insert(int index, T item); 

你可以使用這樣的:

controls.TestItems.Add(4, IC); 
相關問題