Tuesday 22 March 2011

Collection Interview questions

what is Collection?

It is the set of of similar typed objects grouped together.

 Give examples of Generic and non-generic collections?

Non-Generic collection comes under System.Collections namespace.
eg: Arraylist, queue, stack, Sorted list, Hashtable etc

Generic collection comes under System.Collections.Generic namespace.
eg:generic list, generic queue, generic stack etc

What is an ArrayList?

The ArrayList object is a collection of items containing a single data type values.

What is a HashTable?

The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick
searches can be made for values by searching through their keys.

What is SortedList?

The SortedList object contains items in key/value pairs. A SortedList object automatically sorts items in alphabetic or numeric order.

What’s the .NET collection class that allows an element to be accessed using a unique key?

HashTable.

What class is underneath the SortedList class?

A sorted HashTable.

Where are all .NET  Collection classes located ?

System.Collection namespace has all the collection classes available in .NET.

What’s difference between HashTable and ArrayList ?

You can access array using  INDEX value of  array , but  how many times you know the
real value of index.Hashtable provides way of accessing the index using a user identified KEY value , thus removing the INDEX problem.

What are queues and stacks ?
Queue is for  first-in, first-out (FIFO) structures. Stack  is for last-in, first-out (LIFO) structures.

What is the difference between array and arraylist?

1. Size of array is always fixed and should be defined at the time of instantiation of array whereas arraylist size grows dynamically.
2. In array we can store elements of single type of data type whereas in arraylist we can store elements of data types.

No comments:

Post a Comment