gvector1
asked on
Enumeration????
I have a situation in which an enumeration would be perfect, except the underlying value needs to be a string instead of a number. I know there must be a simple solution, but I cannot think of it right off hand. For example:
public enum Fields{PatName, PatDOB, PatAddress};
But I want the value of Fields.PatName to have a string value of "name" and Fields.PatDOB to have a string value of "dob", etc. Do I need to use a hashtable for this. What would be the best way to accomplish this????
Thanks,
public enum Fields{PatName, PatDOB, PatAddress};
But I want the value of Fields.PatName to have a string value of "name" and Fields.PatDOB to have a string value of "dob", etc. Do I need to use a hashtable for this. What would be the best way to accomplish this????
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent solutions. Thank you both.
This works nicely :
public class FieldNames{
public const string PatDOB = "dob";
public const string PatName = "name";
public const string PatAddress = "address";
public static object Parse(string FieldName){
Type t = typeof(FieldNames);
FieldInfo f = t.GetField(FieldName);
if (f == null){
throw new ArgumentException(FieldNam
}
object o = f.GetValue(null);
return o;
}
}