enum

How to compare string to enum type in Java?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an enum list of all the states in the US as following: public enum State { AL , AK , AZ , AR , ..., WY } and in my test file, I will read input from a text file that contain the state. Since they are string, how can I compare it to the value of enum list in order to assign value to the variable that I have set up as: private State state ; I understand that I need to go through the enum list. However, since the values are not string type, how can you compare it? This is what I just type out blindly. I don't know if it's

How to get enum value by keyname

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: public enum aa{ a1=1,a2=2,a3=6,...,a100=203} How to get value like this string att=GetFromDatabase("attribute"); //this return a1 or a2 ... Enum.GetValue(att); 回答1: Solution string name = GetFromDatabase("attribute"); Enum.Parse(typeof(aa),name); 回答2: Something like this should do the trick: aa attEnum = (aa)Enum.Parse(typeof(aa), att); Go to http://msdn.microsoft.com/en-us/library/system.enum.parse.aspx for more details. 回答3: Use Enum.Parse string att=GetFromDatabase("attribute"); //this return a1 or a2 ... Enum.Parse(typeof(aa), att); 文章来源

pass enum to html.radiobuttonfor MVC3

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I Have an Enum Called ActionStatus that has 2 possible values open=0 and closed = 1 public enum ActionStatus { Open, Closed } I want to build radio button group in my edit and create views that uses the enum to populate the radio buttons with a) a default value in the create view and b) the currently selected option in the edit view. Do i need an extension method for this, and has anybody already created one? EDIT: After Darins's answer below this is my Model class namespace Actioner.Models { [MetadataType(typeof(MeetingActionValidation))]

Enum case switch not found in type

匿名 (未验证) 提交于 2019-12-03 08:39:56
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can someone please help me with this. I have the following public enum public enum OfferViewRow { case Candidates case Expiration case Description case Timing case Money case Payment } And the following mutableProperty: private let rows = MutableProperty<[OfferViewRow]>([OfferViewRow]()) In my init file I use some reactiveCocoa to set my MutableProperty: rows <~ application.producer .map { response in if response?.application.status == .Applied { return [.Candidates, .Description, .Timing, .Money, .Payment] } else { return [.Candidates,

How to create ENUM in SQLAlchemy?

匿名 (未验证) 提交于 2019-12-03 08:39:56
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: from sqlalchemy import * from migrate import * meta = MetaData() race_enums = ('asian','mideastern','black','nativeamerican','indian','pacific','hispanic','white','other'); profiles_profiles = Table( 'profiles_profiles', meta, Column('id', Integer, primary_key = True), Column('user_id', Integer, nullable=False, unique=True), Column('race', Enum, race_enums), Column('summary', Text, nullable= True), Column('my_life', Text, nullable= True), Column('to_do', Text, nullable= True), Column('favs', Text, nullable= True), Column('created_at',

Enum class member with interface cannot find methods internally

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm having a strange issue which I'm not sure if it's a compiler problem or my understanding of enums with interfaces. I'm using IntelliJ IDEA 12, building an Android project, and I have a class like this: public class ClassWithEnum { private MyEnum myEnum ; //Trying to access it internally here throws the error public boolean isActionable () { return myEnum . isActionable (); } public enum MyEnum implements Action { ACTIONABLE () { @Override public boolean isActionable () { return true ; } }, NOT_ACTIONABLE () { @Override public

How to check if an enum variable is valid?

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an enum: enum myenum { typeA , typeB , typeC } myenum_t ; Then, a functions is to be called with an enum parameter: int myfunction ( myenum_t param1 ) { switch ( param1 ) { case typeA : case typeB : case typeC : //do the work break ; default : printf ( "Invalid parameter" ); } return 0 ; } But, as myenum_t grows with more and more values, myfunction doesn't seem so elegant. Is there a better way to check if an enum is valid or not? 回答1: A common convention for this is to do something like this: typedef enum { typeA , typeB ,

Underlying type of a C++ enum in C++0x

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been trying to read a bit of the C++ standard to figure out how enum's work. There's actually more there than I originally thought. For a scoped enumeration, it's clear that the underlying type is int unless otherwise specified with an enum-base clause (it can be any integral type). enum class color { red, green, blue}; // these are int For unscoped enumerations, it seems like the underlying type can be any integral type that will work and that it won't be bigger than an int, unless it needs to be. enum color { red, green, blue}; //

C dictionary/map

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to map struct members so I can eliminate if branches in a loop. What is the best way or convention to implement this in C? I suppose it could be a 2 dimensional array instead...then I could map integers to the char keys? char chunk[32]; int n; int i; char *ptr = config; while (*ptr != '\0') { int items_read = sscanf(ptr, "%31[^;]%n", chunk, &n); if(chunk[0] == 'S' && chunk[1] == 'P') { for(i=0;i<GLOBAL_MEAS_CUTOFF; i++) { theMeas[i].signal_path = atoi(&chunk[2]); } } if(chunk[0] == 'T' && chunk[1] == 'L') { for(i=0;i<GLOBAL_MEAS

C# 枚举

元气小坏坏 提交于 2019-12-03 07:32:57
一、简介 枚举是一组命名整型常量;枚举类型是使用 enum 关键字声明的;C# 枚举是值类型。 二、语法 枚举的语法: public enum 枚举名 { 值1, 值2, 值3, ............ } 或者 enum 枚举名 { 值1, 值2, 值3, ............ } public:访问修饰符,公共的公开的,哪都可以访问; enum:关键字,声明枚举的关键字; 枚举名:要符合Pascal命名规范; 将枚举声明到命名空间下面,类的外面,表示这个命名空间下,所以类都可以访问这个枚举; 三、类型转换 我们可以将一个枚举类型的变量跟int类型和string类型互相转换: 1.枚举类型默认是跟int类型相互兼容的,所以可以通过强制类型转换的语法互相转换,当转换一个枚举中没有的值的时候,不会抛异常,而是直接将数字显示出来。 2.如果将枚举类型转换成string类型,则直接调用ToString(). 3.如果将字符串转换成枚举类型则需要下面这样一行代码: (要转换的枚举类型)Enum.Parse(typeof(要转换的枚举类型),"要转换的字符串"); 如果转换的字符串是数字,则就算枚举中没有,也会不会抛异常。 如果转换的字符串是文本,如果枚举中没有,则会抛出异常。 备注: 所有的类型都能够转换成string类型,调用ToString()。 四、实例 using