Xpode.com        Click here to Print this article.

C#/.NET interview Question - Show different types of collection in .NET?

Answer:
 

Collection: - Collections are basically group of records which can be treated as a one logical unit.

.NET Collections are divided in to four important categories as follows.

  1. Indexed based.
  2. Key Value Pair.
  3. Prioritized Collection.
  4. Specialized Collection.
     



Let’s begin with Indexed based and key value pair.
 

Indexed based: - It helps you to access the value of row by using the internal generated index number by the collection.

Key Value Pair: - It helps you to access value by the user defined key.

Below is the example of country collection for Indexed based and key value pair.

When you want to access India through Index based you have to write like below code.

MessageBox.Show(myarray[0]); //for array
MessageBox.Show(mylist[0]);  //for list

Now, when we want to access the same output “India” by Key value pair.

MessageBox.Show(myhash["IND"].ToString()); //for hashtable

Prioritized Collection: -It helps us to get the element in a particular sequence.

Specialized Collection: -It is very specific collections which are meant for very specific purpose like hybrid dictionary that start as list and become hashtable.

For more detail on collections watch the below video.

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

Regards,

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

 



http://
http://

Contributed by:
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

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=379

Click here to go on website