enum string value

P

puzzlecracker

I have string value, and I want to check if enum contains it..

Say I have enum MyTest {
Foo=1,
Bar
}

and is using pass string argument="Foo"; I'd like to check if it in
the enum.

Now I do the following, but I suspect there is an easier way:

foreach (MyTest t in Enum.GetValues(typeof(MyTest )))
{
if (argument== t.ToString())
{
//DO SOMETHING
}
}

Thanks
 
M

Marc Gravell

I shudder to think what the color "Ultraviolate" looks like....

lol - sounds like a title from the "somewhat dubious" section of the
video store...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top