I have a property that returns a HashTable
. I would like to sort it without refactoring my property. Please note: I do not want to return another type.
Not exactly a C# answer but I am sure you can make something of it.
In Perl it is common to "sort" a hash table for use in output to the display.
For example:
print "Items: ";
foreach (sort keys %items) {
print $_, '=', $items{$_}, ' ';
}
The trick here is that Perl doesn't sort the hash, it is sorting a copied list of hash keys. It should be easy enough in C# to extract the hash keys into a list and then sort that list.