Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     

C# and .NET interview questions - Various types of generic collections


There are basically four different types of generic collections which are as follows:-

1. List:-Lists are indexed based Generic Collections. Lists are Generic form of ArrayList.

List helps us to create flexible strong type collection as you can see in below code snippet i have defined List as "int" and "string".

//index based Generic collection            
List<int> ObjInt = new List<int>();         
Console.WriteLine(ObjInt[0]); //accessing the List by internal index based value.            
List<string> ObjString = new List<string>();            

2. Dictionary:-Dictionary are key based generics collection.
                     Dictionary are generic form of Hashtable.

 //key based Generic collection            
Dictionary<int, int> ObjDict = new Dictionary<int,int>();            
Dictionary<int, string> ObjDict1 = new Dictionary<int,string>();            
ObjDict1.Add(3, "feroz is a developer");            
ObjDict1.Add(4, "wasim is a developer");            
Console.WriteLine(ObjDict1[3]); //accessing the dictionary by defined key.

3. Stack:-Stack generic collection allows you to get value in "LIFO"(last in first out) manner.

// Stack             
Stack<string> ObjStack = new Stack<string>();            

4. Queue:-Queue generic collection allows you to get value in "FIFO"(first in first out) manner.

Queue<int> ObjStr = new Queue<int>();            


For more information about generic, please watch the below video.

Please click here to see more C#/ .NET interview questions 

Visit Authors blog for more C# and .NET interview questions

Share this article   |    Print    |    Article read by 23223 times
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles: No related article
Related Interview Questions: No related interview question