Hi There
I am probably missing something fundamental here, but I cannot see a
method to search the values of a generic dictionary so that I can find
the key ? Of course I could enumerate through the Values collection
but that seems a little long winded.
I ended up using a sorted list because it has the IndexOfValue method.
However I don't need the sorting.
What am I missing ? fyi, the class is below
TIA
Bill
_____________________
public abstract class AusStates
{
static SortedList<char, string> stateListing = new SortedList<char,
string>();
public AusStates()
{
stateListing.Add('2', "NSW");
stateListing.Add('3', "VIC");
stateListing.Add('4', "QLD");
stateListing.Add('5', "SA");
stateListing.Add('6', "WA");
stateListing.Add('7', "TAS");
stateListing.Add('A', "ACT");
stateListing.Add('0', "NT");
}
public static char GetStateChar(string itemToLookup)
{
int indexToFind =
stateListing.IndexOfValue(itemToLookup.Trim().ToUp per(CultureInfo.CurrentCulture));
if (indexToFind == -1)
return ' '; //Keep consistent with old design
else
return stateListing.Keys[indexToFind];
}
public static string GetStateTxt(char itemToLookup)
{
int indexToFind = stateListing.IndexOfKey(itemToLookup);
if (indexToFind == -1)
return " "; //Keep consistent with old design
else
return stateListing.Values[indexToFind];
}
}