
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Reversing the Contents of a Sorted List
|
241
The result of using a nullable type in an expression is a null if any nullable type is
null. However, if none of the nullable types is null, the operation is evaluated as it
normally would be. If
DBInt, for example, is set to null, the value placed in Result
will also be null.
See Also
See the “Nullable<T> Generic Class” and “Using Nullable Types” topics in the
MSDN documentation.
4.8 Reversing the Contents of a Sorted List
Problem
You want to be able to reverse the contents of a sorted list of items while also main-
taining the ability to access them in both array and list styles like
SortedList and the
generic
SortedList<T> classes provide. Neither SortedList nor SortedList<T> pro-
vides a direct way to accomplish this without reloading the list.
Solution
Use the ReversibleSortedList<TKey,TValue> class provided for you here. Reversible-
SortedList<TKey,TValue>
is based on the original SortedList<TKey,TValue> class so
that all of the same functionality is preserved, with the additional bonus of being able
to reverse the order of the list easily.
After instantiating a
ReversibleSortedList<TKey,TValue>, the key of which is an int
and the value of which is a string, a series of unordered numbers and their text rep-
resentations are inserted into the list. ...