How to use Asp.Net List
The Collection classes are a set of classes designed specifically for grouping together objects and performing tasks on them. The basic functionality of collection classes are Adding elements to the Collection, Removing elements from the collection, Obtaining number of elements in the collection atc. List class is a Collection member and defined in the System.Collections.Generic namespace.
The C# List < T > class represents a strongly typed list of objects that can be accessed by index. Elements in the List can be accessed using an integer index. Indexes in this collection are zero-based.
List < T >
The parameter T is the type of elements in the list.
Add items in List collection ?
Add Integer values in the List collection
Add String values in the List
Obtaining the number of elements in a List ?
You can use "count" property to know the number of items in the List collection
Retrieve items from List ?
You can retrieve items from List collection by using for loops.
Insert an item in the List ?
You can insert an item in the List by specify its index value like (index,item) .
In the above code the month "March" inserted in the index position 2.
Remove an item from List collection ?
Remove() can use to remove item from List collection.
Check if an item contains in the List collection ?
You can use List.Contains() methods to check an item exists in the List
Copy an Array to a List collection ?
Finally clear method remove all the items from List collection.
The following program shows some operations in List collections
Click the following links to see full source code