i’m working on parsing a text project where in , i have to match the match the text and get the keywords from the text and perform some actions accordingly.
Now , i’m trying to use enum for matching the text Eg. all the conditions, any condition, none, alteast one,and or etc. i’m trying use enum as the key words might change later,
Is it possible to store string values in enum.
public enum condition
{
type1 = "all the conditions",
type2 = "any of the conditions"
}
i know it is not like normal enum usage,can any one help
You could use readonly string properties:
Use it like this:
BUT
This above solution would however NOT work with
switchstatements. In which case you could useconstYou could use it like this:
See this post for static readonly vs const variables.
To Expand on enums (See MSDN):
They have a default underlying type of
int. You can change the underlying type to one of the following integral types :byte, sbyte, short, ushort, int, uint, long, or ulong.Thanks to @Bryan and @R0MANARMY for helping me improve my answer.