12 October 2011

List in C#

List in C#


Namespace used:System.Collections.Generic
The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.


List<string> dinosaurs = new List<string>();
dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
foreach(string dinosaur in dinosaurs)
{
      Console.WriteLine(dinosaur);
}

 dinosaurs.Insert(2, "Compsognathus");//To Insert in List

 dinosaurs.Clear(); //To Clear


No comments:

Post a Comment

Comments Welcome