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

Consistency level in Azure cosmos db

 Consistency level in Azure cosmos db Azure Cosmos DB offers five well-defined consistency levels to provide developers with the flexibility...