Can you insert at position 0 in a List?

后端 未结 4 2008
醉话见心
醉话见心 2021-01-18 05:07

I need to insert an object at the beginning of a collection.

My colleciton is of type List

How can I do this?

4条回答
  •  梦谈多话
    2021-01-18 05:53

    You can use the Insert method.

    List strings = new List { "B", "C", "D" };
    strings.Insert(0, "A");
    

    MSDN documentation: http://msdn.microsoft.com/en-us/library/sey5k5z4.aspx

提交回复
热议问题