C#, MVC Tips and Stuff
A list of things that I have found handy to know...
Tip #1 Boolean Enum Comparison
Not to return an enum value from say an abbreviation to a long string but just to determine if your value is a valid value in the enum list. So you have your Enums declared in a base class or some other class something like this:
public enum MyCustomEnumGroup
{
ABC,
MQP,
RAD,
STY
}
Then wherever you need to check your string to see if the string you are passing in is in the Enum Group call it as shown below, this returns a boolean based on the match to the enumgroup.
if (Enum.IsDefined(typeof(MyCustomEnumGroup),mystringtopassin))
Comments