Tuesday, October 19, 2010

Generics : Part 1

/*
* Note: Please replace "<" with ! and ">" with *
* Generics are Type safe means it gives warning at compile time only not at RunTime
*/
/*
* ================
* List!* generics
* ===============
*/
List !int* lstintCg = new List!int*();
lstintCg.Add(1);
List !string* lststrCg = new List!string*();
lststrCg.Add("1");
/*
* ================
* SortedList!* generics
* ===============
*/
SortedList !int, string* slst = new SortedList !int, string* ();
slst.Add(1, "Value_1");
/*
* ================
* Dictionary!* generics
* ===============
*/
Dictionary !int, string* dict = new Dictionary!int, string*();
dict.Add(26691, "bimlesh.singh@aexp.com");
foreach (KeyValuePair !int,string* kvp in dict)
{
Console.WriteLine("Key : {0}\n value :{1}",kvp.Key,kvp.Value );
}
Console.Read();

No comments: