enums

Can a C# enum entry have a hyphen in the name

Is thre any way to have an enum entry with a hyphen, "-", in the name, for example: enum myEnum { ok, not-ok, } I've seen the question about enums having friendly names however it would save me a bit of work if I can use a hyphen directly. Update: The reason I want to use a hyphen is it makes it easy to use an enum for lists of...

Restrict a string property to a pre-defined set of values (workaround for no hyphens in an enum)

I have a string property that I would like to be able to force two things with: - It can only be set to specific vaues within a pre-defined list, - Error checking of the property's value can be performed at compile time. An enum fits the bill perfectly except that in my list of pre-defined strings there is one with a hyphen and enum v...

How do I get Doxygen to "link" to enum defintions?

I have the following code: /// \file Doxygen_tests.h /** * * \enum Tick_Column_Type * * \brief Values that represent Tick_Column_Type. **/ enum Tick_Column_Type { TC_OPEN, ///< Opening price TC_HIGH, ///< High price TC_MAX, ///< Required as last enum marker. }; /** * * \struct Tick...

Using enum as integer constant in C#

My question is pretty simple, but I didn't find a way to implement my code the way I want it to be. So I started wondering if the code I want to implement is not good. And if it is, what's the best way to do it. Here it goes: class InputManager { SortedDictionary<ushort,Keys> inputList = new SortedDictionary<ushort,Keys>(); ...

Mysql: enum confusion

I have an employee table, employee has interests, so the table can be designed like this: create table emp( id int(10) not null auto_increment, name varchar(30), interest varchar(50), primary key(id) ); or this: create table emp( id int(10) not null auto_increment, name varchar(30), interest enum('football','basketball','music...

C#: Getting lowest valued key in a bitwise Enum

I have enum like this [Flags] public enum Key { None = 0, A = 1, B = 2, C = 4 } I have the following Key k1 = Key.A | Key.B | Key.C; I want to get the key in k1 that has the lowest value. How can I do that? Example: Key k1 = Key.A | Key.B | Key.C; // I want a Key k2 = Key.B | Key.C; // I want b Key k3 = Key.A | Key.C; //...

Easy C enum question

I have just started C very recently and I have been asked to answer some coding exercises in which the following piece of code appears: typedef enum { false = 0, true = 1 } Bool; Could someone please provide a brief and clear explanation to that? Thanks very much. ...

App engine datastore - query on Enum fields.

I am using GAE(Java) with JDO for persistence. I have an entity with a Enum field which is marked as @Persistent and gets saved correctly into the datastore (As observed from the Datastore viewer in Development Console). But when I query these entities putting a filter based on the Enum value, it is always returning me all the entities ...

Source Insight: Show me Enum Values

I'm programming in C and using Source Insight. I have an enum type with a lot of constants (like 100). I have debug prints that print out variable values, but they (of course) print out as integers. What I'd like to do is click on the name of an enum constant, and see its numeric value displayed somewhere. (I've seen this done in a V...

Scala Enumeration values not ordered?

The scala docs say that Enumeration.Val is ordered, however I get inconsistent behavior when when I try to enforce type restrictions on enumeration values requiring them to support ordering: object Dogs extends Enumeration { val Sam, Tom, Rover = Value } def doSomething[A <% Ordered[A]](a : List[A]) : Unit = { println(a.sortWit...

In a C# solution, Where do you declare solution-scope enums ?

In a C# solution, Where do you declare solution-scope enums ? ...

How can I use a special char in a C# enum?

Hello, For example: public enum Unit{ KW, kV, V, Hz, %V } In this case % is a special character. So, how can I put this char in a enum? ...

Trouble with an enumeration as a key in a Dictionary collection

I have a scenario where I'm using a Dictionary to hold a list of transaction types that a certain system accepts. The key in the Dictionary is an enum field, the value is an int. At some point in the system, we're going to want to do something like this: sqlCommand.Parameters.AddWithValue("@param", LookupDictionary[argument.enumField])...

MySQL: Can I Share enums?

I have 3 similar tables, that would all have the same enum type field. Is there a way I can just reuse a single enum instead of creating each (duplicate) enum? Aware of BNF/don't want to use it/small project. ...

Can I overload operators on enum types in C++?

For example, if I have: typedef enum { year, month, day } field_type; inline foo operator *(field_type t,int x) { return foo(f,x); } inline foo operator -(field_type t) { return t*-1; } int operator /(distance const &d,field_type v) { return d.in(v); } Because if I do not define such operators it is actually legal to write da...

Enum.Parse(), Surely a neater way?

Say I have an enum public enum Colours { Red, Blue } The only way i can see of parsing them is doing something like string colour = "Green"; var col = (Colours)Enum.Parse(typeOf(Colours),colour); This will throw a system.argumentexception because "Green" is not a member of the Colours enum. Now I reall...

Why don't my groovy enums work, or even compile?

I'm running Groovy Version: 1.7.0 JVM: 1.6.0_17 (Update -- I just upgraded to 1.7.1 and get the same errors!) I've tried to use enums, using the exact syntax from the groovy documentation, and each time I see the compile error: Groovy:The class java.lang.Enum refers to the class java.lang.Enum and uses 1 parameters, but the referred c...

Easiest way to get Enum in to Key Value pair.

Hi, I have defined my Enums like this. public enum UserType { RESELLER("Reseller"), SERVICE_MANAGER("Manager"), HOST("Host"); private String name; private UserType(String name) { this.name = name; } public String getName() { return name; } } What should be the easiest way to get...

Hibernate - how to map an EnumSet

Hi all, I've a Color Enum public enum color { GREEN, WHITE, RED } and I have MyEntity that contains it. public class MyEntity { private Set<Color> colors; ... I already have a UserType to map my Enums. Do you know how to map a Set of Enums in the Hibernate hbm.xml? Do I need a UserType or there's an easiest way? Thanks ed...

MySQL ORDER BY returns things in (apparently) random order !?

The following query: SELECT DISTINCT ClassName FROM SiteTree ORDER BY ClassName is returning things in no apparent order! I get the same result whether I quote column/table names, or use DISTINCT or not, or add ASC or DESC. I assumed the indexes might be broken, or something like this, so tried dropping and recreating. Also tried RE...