Another helpful Enum method

If you are a C# programmer, chances are that you are using Enum.Parse somewhere in your code. You must be knowing that Enum.Parse throws an exception if you pass an object which is not a member of the enumeration. There are two ways in which you can handle this exception. You either adorn the call to Enum.Parse with try-catch block or use Enum.IsDefined.

I like the latter for obvious reasons. Enum.IsDefined checks if the given object is a valid member of the given enumeration type. If it is, returns true. false, otherwise. So simple, yet so powerful.

Use it and admire it.

Advertisements

One thought on “Another helpful Enum method

  1. Pogo Stick says:

    Is there any better, or easier blog software out there than this? i need something php based that doesnt kill MySQL. Any techie types on this thread that can point me in the right direction?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: