Which collection type should you use?

You are developing an application that includes a class named Order. The application will store a
collection of Order objects.
The collection must meet the following requirements:
Internally store a key and a value for each collection item.
Provide objects to iterators in ascending order based on the key.
Ensure that item are accessible by zero-based index or by key.
You need to use a collection type that meets the requirements.
Which collection type should you use?

You are developing an application that includes a class named Order. The application will store a
collection of Order objects.
The collection must meet the following requirements:
Internally store a key and a value for each collection item.
Provide objects to iterators in ascending order based on the key.
Ensure that item are accessible by zero-based index or by key.
You need to use a collection type that meets the requirements.
Which collection type should you use?

A.
LinkedList

B.
Queue

C.
Array

D.
HashTable

E.
SortedList

Explanation:
SortedList<TKey, TValue> – Represents a collection of key/value pairs that are sorted by key based on
the associated IComparer<T> implementation.
http://msdn.microsoft.com/en-us/library/ms132319.aspx



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Twórca C#

Twórca C#

E jak erekcja

Lord Vader

Lord Vader

sortedlists/dictionaries/hashtables have key/value pairs. so leaves sortedlists adn hashtables.

hashtables can only be accessed by the key and data is stored according to hash code of hte key

sortedlist can be accessed by the key and index because it is sorted. elements in list are sorted by the icomparable implementation of hte key or icomparer implementation when sortedlist is created

E