Tuesday, August 09, 2005

Enum.Parse the right way!

To compare strings with enums the right way, one should use enum.parse rather than comparing string literals. Following is an example where i am parsing a string type variable named messageId and creating an enum of type MessageType

MessageType messageType = (MessageType) System.Enum.Parse(typeof(MessageType),messageId,true);

Last argument in System.Enum.Parse specifies if the enumeration/comparison should be case sensitive or not.

1 comment:

Mohamed Moshrif said...

It's the most funniest way i had ever seen to make an ad for an university degree :D