I need to insert an object at the beginning of a collection.
My colleciton is of type List
How can I do this?
Solution: Use the list. insert(0, x) element to insert the element x at the first position 0 in the list.
The Insert method of List<T> class inserts an object at a given position. The first parameter of the method is the 0th based index in the List. <T>. The InsertRange() method can insert a collection at the given position.
Sure can; for example a generic List of strings:
List<string> values = new List<string>();
values.Insert(0, "NewString");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With