enums

Where to declare an enum struct?

This is just out of curiosity but when i declare an enum type, would it be better to have it within an implementation declaration or outside of it? What would be best practice? For example: @implementation PostQuestionScene enum popUpItems{ kExpiredBox, kPauseBackground }; vs.. enum popUpItems{ kExpiredBox, }; @implementation...

The underlying connection was closed: The connection was closed unexpectedly

When working with WCF many times the exception massage doesn’t help us to solve the problem. The above massage is usually a symptom for one of the following problems: The return values are bigger than the value which was defined in the config file. There is a problem with the endpoint setting There is a problem with serialization of t...

Enum with int value in Java

What's the Java equivalent of C#'s: enum Foo { Bar = 0, Baz = 1, Fii = 10, } ...

When are two enums equal in C#?

I have created two enums and I know they are not the same but still I think it makes sense they would be equal since their string representation as well as their numeral representation are equal (and even the same...). In other words : I would like the first test to pass and the second one to fail. In reality however, they both fail. ...

Two member enumeration vs. boolean value

This question has in the back of my mind for some time, sorry if it appears subjective. There are some disadvantages in using bool in public properties and constructors for data objects. Consider the following code as an example. Using bool: public class Room { public string Name { get; set; } public bool Bookable { get; set; }...

Bitflag enums in C++

Using enums for storing bitflags in C++ is a bit troublesome, since once the enum values are ORed they loose their enum-type, which causes errors without explicit casting. The accepted answer for this question suggests overloading the | operator: FlagsSet operator|(FlagsSet a, FlagsSet b) { return FlagsSet(int(a) | int(b)); } ...

Best way to compare .NET enum values

What's the best way in code to compare enum values? For example, if I have the following enum type: public enum Level : short { Low, FairlyLow, QuiteLow, NotReallyLow, GettingHigh, PrettyHigh, High, VeryHigh, } And I want to be able to write statements such as: from v in values select v where v > L...

WCF: Enforce equal DataContracts on both sides

Hi all, I'm wondering if it is possible to have WCF make sure that the DataContracts on both sides of a connection are exactly the same (and throw an exception when trying to connect if they are not). For example, imagine this service: [DataContract] enum State { [EnumMember] Red, [EnumMember] Yellow, [EnumMember] ...

Using List.Find or LINQ on lists of enums in .NET 3.5

How come List.Find (and LINQ-queries on the list as well) always return the first enum element when the list does not contain the element I am searching for? Scenario: My enum: public enum TestEnum { EnumOne, EnumTwo, EnumThree } My test: var TestEnum1 = TestEnum.EnumOne; var TestEnum2 = TestEnum.EnumTwo; var TestEnum3 ...

Constant Values Required in Variable Declartion

We are using a custom API in our project which provide an attribute for class fields/members which lets the interface to present a popup of some range values like "On/OFF" and pass the corresponding values of the choice to our code. The attribute requires a string array to know that values. We have many enumerations defined for these ra...

Issue getting Doxygen to document an enum in C

I have a rather odd problem with Doxygen (1.6.1 on Mac OS X Snow Leopard) in that it does not seem to document my enums no matter what I do. I am programming in C and have followed the instructions in the manual. Here is my code: /** * \enum dccp_pkt_type * \brief specifies the available DCCP packet types */ enum dccp_pkt_type { ...

C++: Equivalent to "using namespace <namespace>" but for classes?

Suppose you have a class with an enum defined within it: class MyClass { typedef enum _MyEnum{ a } MyEnum; } Is there a way to access the value a from another class without having to refer to it as MyClass::a? If the enum were contained within a namespace rather than a class, than "using namespace ;" solves the problem - is there a...

C++ enum value initialization

I have an enum declared in my code as: enum REMOTE_CONN { REMOTE_CONN_DEFAULT = 0, REMOTE_CONN_EX_MAN = 10000, REMOTE_CONN_SD_ANNOUNCE, REMOTE_CONN_SD_IO, REMOTE_CONN_AL, REMOTE_CONN_DS }; I expect the value of REMOTE_CONN_SD_IO to be 10002, but when debugging the value of ((int)REMOTE_CONN_SD_IO) was given as ...

how to use the toString() method for multiple enum members in same class in Java

I am trying to add more user friendly descriptions for multiple enum members in the same class. Right now I just have each enum returned in lowercase: public enum Part { ROTOR, DOUBLE_SWITCH, 100_BULB, 75_BULB, SMALL_GAUGE, LARGE_GAUGE, DRIVER; private final String description; Part() { description = toString()....

How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String description; Letter() { description = toString(); } Letter(String description) { this.description = description; ...

Enum scoping issues

I try to keep things as local as possible, so I put enums at class scope, even if they are shared between two classes (I put it in the class that "goes better" with it.) This has worked out great, but I recently ran into an issue where a circular dependency will occur if I put the enum at class scope. The enum is going to be a construct...

Pass enums by value or reference?

My general rule is to pass by value for primitive types and pass by reference for objects (obviously const'd if need be). However, I'm not sure what route to take with enumerated types. I'd assume that pass by value is preferred since they are seemingly small, but I'd like to hear others thoughts. ...

Subclass check, is operator or enum check

Hi A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a abstract enum in the base class to be used for checking the type of the subclass, or if you should use the is operator. Alt 1. public ...

Enum values().length vs private field

I have enumeration like this: public enum Configuration { XML(1), XSLT(10), TXT(100), HTML(2), DB(20); private final int id; private Configuration(int id) { this.id = id; } public int getId() { return id; } } Sometimes I need to check how many fields I have in enumeration. What is the best solution? Should I use a method "...

Conversion of Enum to Enumerable

To convert Enum to Enumerable ,I use public enum Flags { Trivial=1, Minor, Major, Critical } IEnumerable<int> n = Enumerable.Range((int)Flags.Trivial, (int)Flags.Critical).OfType<int>(); Just I want to know whether it is a valid conversion or not (code is working). ...