Associate two sets of values
- by PJW
I have the following code -
public static int GetViewLevel(string viewLevelDesc)
{
try
{
switch (viewLevelDesc)
{
case "All":
return 0;
case "Office":
return 10;
case "Manager":
return 50;
default:
throw new Exception("Invalid View Level Description");
}
}
catch (Exception eX)
{
throw new Exception("Action: GetViewLevel()" + Environment.NewLine + eX.Message);
}
}
public static string GetViewLevelDescription(int viewLevel)
{
try
{
switch (viewLevel)
{
case 0:
return "All";
case 10:
return "Office";
case 50:
return "Manager";
default:
throw new Exception("Invalid View Level Description");
}
}
catch (Exception eX)
{
throw new Exception("Action: GetViewLevelDescription()" + Environment.NewLine + eX.Message);
}
}
The two static Methods enable me to either get an int ViewLevel from a string ViewLevelDesc or vice versa. I'm sure the way I have done this is far more cumbersome than it needs to be, and I'm looking for some advice how to achieve the same objective but more concisely. The list of int / string pairs will increase significantly. The ones in the above code are just the first three I intend to use.