Add an item to the beginning of a List The List class represents a strongly typed list of objects. This class provides methods to search, sort, and manipulate lists. The List class is the generic equivalent of the ArrayList class. The list is not guaranteed to be sorted. Elements of a list can be accessed using an integer index and the indexes are zero-based. The list accepts null as a valid value for reference types and allows duplicate elements. The following .net c# tutorial code demonstrates how we can add an item to the beginning of a List instance. But there is no direct method to add an item to the beginning of a list. So we have to apply a trick to achieve it. We will insert an item at the zero index position of a list that will add the item to the list beginning. Here we will use the List class Insert() method to add an item to the list first. The List class Insert(Int32, T) method inserts an element into the List at the specified index. The ...
Android, .NET C#, Flutter, and Many More Programming tutorials.