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

Finding duplicate records in SQL Server

 Finding duplicate records in SQL Server 1. The GROUP BY and HAVING Method This is the most standard approach. It is best used when you on...