Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




.NET interview questions: - What are different types of collections in .NET?

There are five important collections in .NET Arrays, Lists, Hashtable, stacks and queues.

Arrays and Lists

  • Arrays are fixed in size while Arraylist is resizable.
  • Arrays are strongly typed, in other words when you create an array it can store only one data type data. Arraylist can store any datatype.

Hashtable collections

  • In arraylist or array if we have to access any data we need to use the internal index id generated by the array list collection. For instance the below code snippet shows how the internal id is used to fetch data from array list.
  • In actual scenarios we hardly remember internal id’s generated by collection we would like to fetch the data by using some application defined key. There’s where hash table comes in to picture.

string str = MyList[1].ToString();

  • Hash table helps to locate data using keys as shown below. When we add data to hash table it also has a provision where we can add key with the data. This key will help us to fetch data later using key rather than using internal index id’s generated by collections.

objHashtable.Add(“p001”,”MyData”);

This key is converted in to numeric hash value which is mapped with the key for quick lookup.

Queues and stack collections

  • Queues are collection which helps us to add object and retrieve them in the manner they were added. In other word queues helps us to achieve the first in first out collection behavior.
  • Stack collection helps us to achieve first in last out behavior.

Also see following .NET interview questions video on concurrent generic collections in C#: -

Helpful Website Url
http://www.questpond.com/
Share this article   |    Print    |    Article read by 6373 times
Author:
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 http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: