English 中文(简体)
Converting to enum in Linq tokou
原标题:Convert string to enum in Linq to SQL

如何利用C#在Linq将扼杀变成um?

下面的类型是否也在林木中发挥作用?

(Audience)Enum.Parse(typeof(Audience), value, true);

如果是的话,请告诉我我我我我如何能够这样做?

最佳回答

考虑到 the

enum Foo{A, B, C}

以下代码从<代码>enum 改为string,反之亦然:

var values = 
from name in Enum.GetNames(typeof(Foo))
select (Foo)Enum.Parse(typeof(Foo), name, true);

因此,是成品。 但是,铭记以上所述问题,如果<代码>Enum.Parse 方法得到的数值不能平价,则将丢下<条码>。

这一更新版仅是按原样推定的回归价值。

enum Foo{A, B, C}

var values =  
   from name in Enum.GetNames(typeof(Foo))
   where Enum.IsDefined(typeof(Foo), name)
   select (Foo)Enum.Parse(typeof(Foo), name, true);
问题回答

暂无回答




相关问题
Forcing a datatype in MS Access make table query

I have a query in MS Access which creates a table from two subqueries. For two of the columns being created, I m dividing one column from the first subquery into a column from the second subquery. ...

How to convert / cast long to String?

I just created sample BB app, which can allow to choose the date. DateField curDateFld = new DateField("Choose Date: ", System.currentTimeMillis(), DateField.DATE | DateField.FIELD_LEFT); After ...

Converting an Integer to Enum in PostgreSQL

I have created a custom data type enum like so: create type "bnfunctionstype" as enum ( normal , library , import , thunk , adjustor_thunk ); From an external data ...

Convert Session Object to IOrderedQueryable<T>

I need to convert a Session object to an IOrderedQueryable and came up blank. I ve thought of creating a wrapper, but its not working properly. Basically, I am pulling a Linq query and would like to ...

WPF binding with explicit conversion

My question may be a repeat of other conversion question but I feel mine is different. Here goes... [simplified example]. public class DataWrapper<T> { public T DataValue{ get; set; } ...

String in scientific notation C++ to double conversion

I ve got a database filled up with doubles like the following one: 1.60000000000000000000000000000000000e+01 Does anybody know how to convert a number like that to a double in C++? Is there a "...

热门标签