views:

37

answers:

1

I have a hashtable with id-name value pairs. the id is entered as the key, and the name as the value. I am then searching the table, and returning the key whose value matches a specified string like this: (folderValue is the specified string)

String^ key;
for each (String^ aKey in table.Keys)
{
    if ((String^)table.default[aKey] == folderValue)
    {
        key = aKey;
        break;
    }
}

My question is, there might be more than one value that matches folderValue. Is there any way to start searching from the most recent entries and back?

TIA

+2  A: 

That's a fairly non-standard way to use a hashtable. How are you using this data? Consider alternate data structures, like perhaps a List<MyCustomClass>, where MyCustomClass contains ID, Name, and implements IComparable that considers a date or other time-based data. Retrieve items from this list, and sort them. Using LINQ against this would give you a nice way to retrieve data.

Michael Petrotta