
This is a snippet I use to retrieve the integer value from an enumeration
Instructions: Pass the value you're looking for, and the enumeration to search, and it will return the integer value of the enumeration.
/// <summary>
/// Fnction to return the text value based on the index provided
/// </summary>
/// <param name="_enum">Enum to work with</param>
/// <param name="name">The value we're looking for</param>
/// <returns></returns>
/// <remarks></remarks>
public static string GetStringValue(Type _enum, string name)
{
string str = string.Empty;
//get the names from the enumeration
string[] names = System.Enum.GetNames(_enum);
//get the values from the enumeration
int[] values = System.Enum.GetValues(_enum);
//Now we loop through all the names in the enum list
//looking for a match
for (int i = 0; i <= names.Length - 1; i++)
{
//If this current index matches the name
//then we return that name
if (names[i] == name)
{
str = names[i;
break;
}
}
return str;
}-Offline- |