J
Jeff Johnson
Unless a project particularly interests me, I'll try to see if someone else
has created what I need rather than doing it myself. Such is the case now.
I'm wondering if anyone has made a list/array class (preferrably a generic
one) that holds IComparable[<T>] objects and automatically sorts the list
when a new object is added. I know there is the SortedList<TKey, TValue>
class (and SortedDictionary), but I don't want a key/value pair; I simply
want this list to contain a value and always return those values in sorted
order. For example, I want to do this:
private SortedArray<string> mySortedArray = new SortedArray<string>();
mySortedArray.Add("Orange");
mySortedArray.Add("Peach");
mySortedArray.Add("Banana");
mySortedArray.Add("Apple");
foreach (string fruit in mySortedArray)
{
Debug.WriteLine(fruit);
}
and have the output be
Apple
Banana
Orange
Peach
without ever having to call mySortedArray.Sort() or anything like that. Has
someone done this? Am I totally blind and can't find it in the base class
library even though it's right under my nose?
has created what I need rather than doing it myself. Such is the case now.
I'm wondering if anyone has made a list/array class (preferrably a generic
one) that holds IComparable[<T>] objects and automatically sorts the list
when a new object is added. I know there is the SortedList<TKey, TValue>
class (and SortedDictionary), but I don't want a key/value pair; I simply
want this list to contain a value and always return those values in sorted
order. For example, I want to do this:
private SortedArray<string> mySortedArray = new SortedArray<string>();
mySortedArray.Add("Orange");
mySortedArray.Add("Peach");
mySortedArray.Add("Banana");
mySortedArray.Add("Apple");
foreach (string fruit in mySortedArray)
{
Debug.WriteLine(fruit);
}
and have the output be
Apple
Banana
Orange
Peach
without ever having to call mySortedArray.Sort() or anything like that. Has
someone done this? Am I totally blind and can't find it in the base class
library even though it's right under my nose?