0
A
回答
6
您可以使用List.Insert()
的是,它需要在要添加新項目的指標,即在開始添加:
list.Insert(0, item);
而且在同一時間加入多個項目您可以使用List.InsertRange()
這需要一個IEnumerable
作爲第二個參數:
list.InsertRange(0, itemCollection);
+0
不要忘記list.InsertRange – Pete 2011-03-29 01:39:14
3
你可能想InsertRange。
2
List<int> listOfMonths = new List<int>();
// ... insert months here
listOfMonths.InsertRange(0, new int[] { 1, 2 ,3 });
0
讓我們發瘋......
// in a static class in a namespace you can see
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> second, IEnumerable<T> first)
{
foreach (var x in first)
{
yield return x;
}
foreach (var x in second)
{
yield return x;
}
}
...
var newListOfMonths = listOfMonths.Prepend(someExtraItems).ToList();
相關問題
- 1. C#列表 - 添加到列表底部
- 2. 添加列表項到列表在c#
- 3. 將項目添加到C++列表中
- 4. Python添加到列表中
- 5. 將項添加到列表<> c#
- 6. C#如何添加到列表類?
- 7. 將列表添加到c#TreeView
- 8. 凍結添加到鏈接列表(C)
- 9. C#sp2010將項目添加到列表
- 10. 將多個列添加到MySQL的C#列表中選擇
- 11. C#將項目添加到列表中,然後將列表項添加到列表框
- 12. 添加到列表
- 13. c#將列添加到列表框並清除列表項
- 14. 列表添加到Excel列
- 15. 列添加到列表
- 16. 添加到列表中的對象最終添加到所有列表對象
- 17. 添加列表gtk_tree_view用C
- 18. 將節點添加到C++中的鏈接列表中
- 19. 在c#中添加一列到IEnumerable中#
- 20. 將元素添加到鏈接列表中的鏈接列表中C
- 21. 動態添加列到列表中
- 22. 將陣列添加到列表中
- 23. 添加到列表中的理解
- 24. 項添加到列表中的角
- 25. 添加到列表中的整數
- 26. 未添加到列表中的商品
- 27. C# - 將數據添加到列表內部列表
- 28. + =在C++中的運算符添加Autors到列表
- 29. 將對象添加到子類中的列表(C#)
- 30. 將列添加到C#中的數據表?
當你說列表中,你的意思System.Collections.ArrayList,System.Array的,月[],System.Collections.Generic.List, System.IEnumerable 還是別的?根據您返回的類型,解決方案可能會有很大差異。 –
earlNameless
2011-03-29 01:35:04