enums

C/C++ enums: Detect when multiple items map to same value

Is there a compile-time way to detect / prevent duplicate values within a C/C++ enumeration? The catch is that there are multiple items which are initialized to explicit values. Background: I've inherited some C code such as the following: #define BASE1_VAL (5) #define BASE2_VAL (7) typedef enum { MsgFoo1A = BASE1_VAL, ...

C# Event Handlers Using an Enum

I have a StatusChanged event that is raised by my object when its status changes - however, the application needs to carry out additional actions based on what the new status is. e.g If the new status is Disconnected, then it must update the status bar text and send an email notification. So, I wanted to create an Enum with the possibl...

Declaring an enum as a class member

Is there any mechanism in C# that allows one to define and declare an Enum variable in the same line like so: public class ClassWithEnumMember { public Enum Type { TYPE1, TYPE2, TYPE3 } = TYPE1; } ...

Signedness of enum in C/C99/C++/C++x/GNU C/GNU C99

Hello Is enum type signed or unsigned? Is the Signedness of enums differ in C/C99/ANSI C/C++/C++x/GNU C/ GNU C99? Thanks ...

Fluent Nhibernate expression to select on flagged enum

I have a domain entity that has a flagged enum as a property. The flagged enum is the target audience for the these entities. The user then has a flagged enum value of the entities they should see. I am trying to figure out the correct expression to select entities that meet the target audience for the user. public class File { pu...

Obj-C Error: Expected expression before ...... (why?)

Hi I have an enum declared like this: typedef enum { Top, Bottom, Center } UIItemAlignment; In my code I try to use it like this: item.alignment = UIItemAlignment.Top; I get an error like this: " Expected expression before 'UIItemAlignment' " If I use only: item.alignment = Top; everything works fine bu...

Count enumerated values?

If my table looks like this: daily_individual_tracking', 'CREATE TABLE `daily_individual_tracking` ( `daily_individual_tracking_id` int(10) unsigned NOT NULL auto_increment, `daily_individual_tracking_date` date NOT NULL default ''0000-00-00'', `sales` enum(''no'',''yes'') NOT NULL COMMENT ''no'', `repairs` enum(''no'',''yes'') ...

Enum "copy" problem

Hi all! I have a class, let's call it A. It has a enum (E) and a method Foo(E e), with gets E in the arguments. I want to write a wrapper (decorator) W for A. So it'll have its own method Foo(A::E). But I want to have some kind of encapsulation, so this method should defined as Foo(F f), where F is another enum defined in W, that can be ...

Using enums or a set of classes when I know I have a finite set of different options?

Let's say I have defined the following class: public abstract class Event { public DateTime Time { get; protected set; } protected Event(DateTime time) { Time = time; } } What would you prefer between this: public class AsleepEvent : Event { public AsleepEvent(DateTime time) : base(time) { } } public class A...

How to use enumeration types in C++?

I do not understand how to use enumeration types. I understand what they are, but I don't quite get their purpose. I have made a program that inputs three sides of a triangle and outputs whether or not they are isosceles, scalene, or equilateral. I'm suppose to incorporate the enumeration type somewhere, but don't get where and how to u...

Databinding an enum to a ComboBox in WPF + MVVM

I've read this very related question here on SO, and it was extremely helpful because of the link in the answer. I'm just having a problem now going the extra step and making it all work with the MVVM pattern. Let's say I have my ViewModel, and it (or even the Model) could have an enum defined: public enum MyTypes { Type1, Type2, Type...

Custom Data Types

Hello, quick question: I'd like to create some custom data types, but I don't think I'm asking the right question(s). There are "compound Boolean" values used throughout .NET, and I want to design some of my own. I've been using a series of Boolean variables, which works, but just isn't the same. Examples from .NET include: Color.Blac...

Why use int in enum declaration?

What's the point of using : int in the enum declaration as following? public enum AAType : int { Folder = 0, File = 1, Link = 2 } ...

How do I use unsafe values in an enum?

I need to use this enum in my C# application, but it won't let me use these values. When I specify the type as uint I can use the -1 value, and when I specify int I can't use the last 2 values. Is there a way to use the unchecked keyword here to allow me to define all of these values? These values are coming from an external source, so I...

Exposing .NET enums to COM clients{VBScript}

Am trying create of PoC for exposing/invoking various .NET objects from COM clients. The .NET library contains some classes and Enums. Am able to successfully access the classes in VBScript but not able to access the Enums. I know that Enums are value types and hence 'CreateObject' wont work in this case. But am able to access the sam...

C# Enum Declaration Format

im new to this and would like to develop sound programming practices. i am wondering if members of an Enum declaration should be all uppercase or just the first letter? thank you. ...

How to deal with calculated values with Dependency Properties on a custom WPF control

To summarize what I'm doing, I have a custom control that looks like a checked listbox and that has two dependency properties one that provides a list of available options and the other that represents a enum flag value that combines the selection options. So as I mentioned my custom control exposes two different DependencyProperties, ...

Iterate over enum?

I'm trying to iterate over an enum, and call a method using each of its values as a parameter. There has to be a better way to do it than what I have now: foreach (string gameObjectType in Enum.GetNames(typeof(GameObjectType))) { GameObjectType kind = (GameObjectType) Enum.Parse(typeof (GameObjectType), gameObjectType); IDicti...

Versions of Enum

Hi, I've got Enum: public enum ObjectType { Country=0, Region=1, Province=2, City=3, Hotel=4 } I have two applications in two language versions, and this Enum is displaying in some place, so depends of language version I wanna displaying correct version of Enum in german version instead Country Land etc. This App...

How to nest an Enum inside the value of an Enum

I'd like to know if it is possible in Java to nest Enums. Here what i'd like to be able to do : Have an enum Species made of CAT and DOG wich would grant me access to sub enums of the available CAT and DOG breeds. For example, i'd like to be able to test if wether a CAT or a DOG and if an animal is a PERSAN CAT or a PITBULL DOG. CAT an...