enums

Elegant way to match an int to an enum where each enum type corresponds to a range

I am trying to think of an elegant way to solve this problem in Java: Given an int of 0-100 what is an elegant way to turn it into an enum where each of the enum's possible values correspond to a range of ints. For example enum grades{ A -> 90-95% B -> 85-90%, C -> 75-85% ... etc } Can anybody think of a concis...

Enum to Int. Int to Enum . Best way to do conversion?

public Enum Days { Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7 } Now I wanted to know how do I get the integer value of an enum and convert an integer value into enum Will int dayNo = (int) Days.Monday; change the value of dayNo to 1; and Will ...

What's wrong using self defined enums versus system enums when binding wpf data

Hello everybody, I was trying follow almost all tutorials regarding wpf data binding, I stil have problem to bind a comboBox with enum property which defined by me in a different namespace. The enum: namespace H3S.Interopability { public enum eDataBits { DataBits5 = 5, DataBits6 = 6, DataBits7 = 7, D...

.NET Enumeration allows comma in the last field

Why in this planet .NET enumeration are allowed to have comma in the last field? Is this has any special meaning? [FlagsAttribute] public enum DependencyPropertyOptions : byte { Default = 1, ReadOnly = 2, Optional = 4, DelegateProperty = 32, Metadata = 8, NonSerialized = ...

Defining C# enums with descriptions

What would the folowing VB.NET enum definition look like in C#? Public Enum SomeEnum As Integer <Description("Name One")> NameOne = 1 End Enum ...

Can we make a enum as a generic data type?

Can we make a enum as a generic data type? If so please provide an example. Thanks in advance. ...

WPF Binding Enum to Command Parameters

I am trying to bind a Enum to CommandParameters of a button. This cannot be static due to the fact that the button occurs in a ItemsControl. Here is the Datatemplate: <DataTemplate> <Button Command="{Binding MyCommand}" CommandParameters="{Binding MyEnumParameter}" Text="{Binding MyText}" /> </DataTemplate> I am not sure what I n...

Enum in Hibernate, persisting as an enum

In my MySQL database, there's the column "gender enum('male','female')" I've created my enum "com.mydomain.myapp.enums.Gender", and in my Person entity I'm defined "Gender gender". Now I'd want to keep the enum type in my MySQL database, but when I launch my application I get: Wrong column type in MyApp.Person for column Gender. F...

Can I display the value of an enum with printf()?

Is there a one-liner that lets me output the current value of an enum? ...

Two enums have some elements in common, why does this produce an error?

enum Month {January, February, March, April, May, June, July, August, September, October, November, December}; enum ShortMonth {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; May is a common element in both enums, so the compiler says redeclaration of enumerator `mei'. Why? And how can I circumvent this? ...

WPF: Storing a radio button selection in the settings

I've been looking at this article but am having issues saving the enumerated value in the settings. I have created the following enum public enum FType { None, Delimited, FixedWidth, XML }; I have the radio button selection working nicely but I now want to store the selected option in the settings but there doesn't ap...

Java Enums - Switch statements vs Visitor Pattern on Enums - Performance benefits?

I have been searching around for days to find an answer to this performance based issue. After digging the Internet so far I have learned that there are couple of ways to use the Enums in java, well documented in here. Well, definitely as a starter one would like use Enums in a switch-case statement, which provides clarity and better un...

Java - Can you access an Enum declared in Subclass from Super class?

I was hoping to declare in Enum type in a subclass and then access it from the super class. This is what I came up with, but it does not work: class Subclass { enum Pets { CAT, DOG; } Class<Pets> getEnumClass() { return Pets.class; } } class Superclass { // This generates a warning: abstract Class<? extends Enum> ge...

Do I need a converter to parse and bind an enum

In my database I have a 2 columns (Kind and Priority) that are of type int. I also have an enum with the values of Kind and Priority. But when I try to display them into a GridViewColumn, it shows the integers and not the enum values. Do I need a converter Here is the enums: public enum Kind { None = 0, Task = 1, Assignment ...

Is there a way to find the cardinality (size) of an enum in C++?

Could one write a function that returns the number of elements in an enum? For example, say I have defined: enum E {x, y, z}; Then f(E) would return 3. ...

How to enumerate an enum/type in F#

I've got an enumeration type defined like so: type tags = | ART = 0 | N = 1 | V = 2 | P = 3 | NULL = 4 is there a way to do a for ... in tags do ? This is the error that I'm getting: The value, constructor, namespace or type tags is not defined ...

How can I read contents from Spring Messagesource within a Enum?

I have an Enum containing three different Status types. These statuses should be displayed in an email sent to users, and the strings containing the statuses to be displayed are stored in messages.properties (read using an implementation of Spring class org.springframework.context.MessageSource). This works well in a normal Spring contro...

Custom enum as application setting type in C#?

If have an enum in C#: [Serializable] public enum OperatingSystem { Windows, Macintosh } For my application I use the application settings, where I can select of which Type a setting should be. I thought when I select Browse, I could choose my enum or type the fully qualified path to select that enum as the Type. Edit: I se...

Using enum with string variables

Hi, I'm trying to do something like this, enum Data_Property { NAME, DATETIME, TYPE, }; struct Item_properties { char* Name; char* DateTime; int Type; }; int main() { std::string data = "/Name Item_Name /DATETIME [TimeStamp] /TYPE [Integer value]"; std::list <std::string> known_properties; known_properties.push_back("/Na...

Cleaner way to cast a C# enum

I want to use an object (returned by framework, not in my control), myField which has a property DisplayFormat of type enum SPNumberFormatTypes. I want to assign the integer value of DisplayFormat as a string to an XmlAttribute. Here is what I currently do: myAttribute.Value = ((Int32)((SPNumberFormatTypes)field.DisplayFormat)).ToStrin...