473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Enum.Parse()

Is this the hardest method in the entire .NET class lib?

Seems like it works differently for different enumTypes

I code

SearchRequest.SafeSearch =
(SafeSearchOptions)Enum.Parse(SafeSearchOptions,"m oderate",true);

and it tells me that "SafeSearchOptions is a type but is used like a
variable".

But the Enum.Parse() docs say that the 1st param should be an enumType !

This is bewildering.
Apr 5 '06 #1
3 4011
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote:
SearchRequest.SafeSearch =
(SafeSearchOptions)Enum.Parse(SafeSearchOptions," moderate",true);
and it tells me that "SafeSearchOptions is a type but is used like a
variable".
But the Enum.Parse() docs say that the 1st param should be an enumType !


The docs mean it should be a System.Type, one that represents an
enumeration. So presumably
Enum.Parse(typeof(SafeSearchOptions),...);

--
Lucian
Apr 5 '06 #2
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in news:
#R*************@TK2MSFTNGP05.phx.gbl:
SearchRequest.SafeSearch =
(SafeSearchOptions)Enum.Parse(SafeSearchOptions,"m oderate",true);

and it tells me that "SafeSearchOptions is a type but is used like a
variable".


MyEnum.Member var = (MyEnum) Enum.Parse(typeof(MyEnum), "whatever");

--
Klaus H. Probst, MVP
http://www.simulplex.net/
Apr 6 '06 #3
SP

"D.S. Fallow" <ms****@msnews.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in news:
#R*************@TK2MSFTNGP05.phx.gbl:
SearchRequest.SafeSearch =
(SafeSearchOptions)Enum.Parse(SafeSearchOptions,"m oderate",true);

and it tells me that "SafeSearchOptions is a type but is used like a
variable".


MyEnum.Member var = (MyEnum) Enum.Parse(typeof(MyEnum), "whatever");


If you are using .Net 2.0 then you can use the following method. Put it in a
utility class.

public static T ParseEnum<T>(string s)
{
return (T)Enum.Parse(typeof(T), s);
}

Apr 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
by: Anonieko Ramos | last post by:
Answer: http://weblogs.asp.net/tims/archive/2004/04/02/106310.aspx by Tim Sneath I've come across the situation on a number of occasions when coding where I've wanted to convert from a string...
8
by: cadilhac | last post by:
Hi, I have the following code: public enum MyColors { Red, Green, Blue } MyColors c = (MyColors)Enum.Parse(typeof(MyColors), "abcd"); Why do I get c = "abcd" after this code instead of...
2
by: wapsiii | last post by:
I'm trying to do this http://geekswithblogs.net/jawad/archive/2005/06/24/EnumDropDown.aspx public enum Color { RED, GREEN, BLUE }
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
8
by: kc | last post by:
I'm trying to pull data from a database that I have no control over the structure of. There's a members table with a column for the member's sex. It just stores the sex as M or F. I'd like to...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: shapper | last post by:
Hello, I have an enum: Public Enum Color Red Blue Green End Enum
5
by: kjqua | last post by:
Hi all, I am newbie in c# and i have a question. I try to work with serial port. and i will like to configure the serial port by a form I add in a ComboBox.parity some items like: None Odd
10
by: Doug | last post by:
I have an enum that will look kind of like this: private enum MyEnum { SomeValue = 0, AnotherValue = 1, ThirdValue = 2 }
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.