enums

String or Enum

Which situation is better? Assuming upwards of 300 possible values on what would essentially be a table of key/value pairs where the column in question is the key: Enum or Char/Varchar I'm just wondering if anyone has dealt with an Enum column with that many possible values and what the pitfalls might be. EDIT: Keys ARE predefined. ...

Using Enumeration in Select case

Enum age Over18 Under18 End enum Select case age End select 'age' is a type and cannot be used as an expression. Is there any way of using enums in "select case"? ...

How do I use my enumeration in a LinqToSQL query?

I have a field in my database table that use to store an enumeration value, e.g.: create table MyTable ( ... Status tinyint not null, ... ) and in my C# class I have public enum TStatus : byte { Pending = 1 Active = 2, Inactive = 3, } public TStatus MyStatus { get { return (TStatus)Status; } set { Status = (byt...

C# Enum values

I have a enum containing the following (for example): UnitedKingdom, UnitedStates, France, Portugal In my code I use Country.UnitedKingdom but I want to have the value be UK if I assign it to a string for example. Is this possible? ...

Is there a way to map an enumeration to another enumeration in C#.NET 3.5?

I'm trying to set up an enumeration that maps certain project-specific values to the standard System.Drawing.Color enum. Here's the idea of what I'd like to do: public enum SessionColors { Highlights = Color.HotPink, Overlays = Color.LightBlue, Redaction = Color.Black } The goal is to have it so I can use Session...

Enum storage in Database field

Is it best to store the enum value or the enum name in a database table field? For example should I store 'TJLeft' as a string or a it's equivalent value in the database? Public Enum TextJustification TJLeft TJCenter TJRight End Enum I'm currently leaning towards the name as some could come along later and explicitly assign a di...

Entity, Value object or enum representation of objects within domain model

Hi, I'm trying to build a document management system and despite all the thigns i've read about entities, value objects, how to choose between how to map them etc... i still can't figure out what the "correct" way to do it is. Quite typically in such a scenerio, each document can beong belong to one or more categories, can be viewed by...

How do you pass multiple enum values in C#?

Sometimes when reading others' C# code I see a method that will accept multiple enum values in a single parameter. I always thought it was kind of neat, but never looked into it. Well, now I think I may have a need for it, but don't know how to set up the method signature to accept this work with the values in the method define the en...

C# boxing enum error with generics

I don't understand what is going on here... I've got the following error: The type 'TestApp.TestVal' cannot be used as type parameter 'T' in the generic type or method 'TestApp.SomeClass<T>'. There is no boxing conversion from 'TestApp.TestVal' to 'System.IComparable<TestApp.TestVal>'. This error happens for the following code: publi...

C# enum in interface/base class ?

Hi, i have problem with enum I need make a enum in base class or interface (but empty one) class Base { public enum Test; // ??? } and after make diffrent enums in some parent classes class Parent1 { public enum Test {A, B, C}; } class Parent2 { public enum Test {J, H, K}; } and now i have next class with method when...

How can I get an enum value from its description?

I have an enum representing all material assembly codes in the system: public enum EAssemblyUnit { [Description("UCAL1")] eUCAL1, [Description("UCAL1-3CP")] eUCAL13CP, [Description("UCAL40-3CP")] eUCAL403CP, // ... } In legacy code in another part of the system, I have objects labeled with strings that match th...

Converting a string to an enum in C#

Possible Duplicate: Converting a string to an enumeration value in C# How do I convert a enum to a string in C#? Note: I have the answer and will post, I searched for the answer here first but couldn't find it so I thought I would add the question / answer to the site once I found it. ...

How do you implicitly convert a string value to an enumeration using LinqToSql?

I asked a previous question about mapping an enumerated value on a table using LinqToSql and the answer was to use the O/R Designer to set the type to global::MyNamespace.TMyEnum. That works OK if your enumeration is based on an integer. But what if your enum is based on a string value? The most obvious application of this is: public...

Enum in DataSet

I'm using DataSet to connect my C# program with SQL database. I want one of the columns to be an enumeration and I want it to act as an enum in my code. How can I do this? ...

Is there a way to declare an annotation attribute for *any* enum?

At the moment I am developing an annotation-based binding-framework for Java Swing that uses JGoodies Binding under the hood. Unfortunately I am stuck with an annotation for a JRadioButton-binding. What I want to do is specify a property-name of a model which holds a special value (enum). The radio-button shall be selected if this proper...

Alternative to enum in Java 1.4

Since Java 1.4 doesn't have enums I'm am doing something like this: public class SomeClass { public static int SOME_VALUE_1 = 0; public static int SOME_VALUE_2 = 1; public static int SOME_VALUE_3 = 2; public void receiveSomeValue(int someValue) { // do something } } The caller of receiveSomeValue...

VB6 IDE is changing the case of my enumeration names

I'm required to maintain a few VB6 apps, and I have run into a weird problem when it comes to enumeration names. The way Intellisense in VB6 is supposed to work is that if my variable name is defined as, say, Dim Abraxis as String, and I type abraxis while coding, the IDE changes it to Abraxis on the fly as I leave the word. However, I...

Switch on Enum (with Flags attribute) without declaring every possible combination ?

Hello, how do i switch on an enum which have the flags attribute set (or more precisly is used for bit operations) ? I want to be able to hit all cases in a switch that matches the values declared. The problem is that if i have the following enum [Flags()]public enum CheckType { Form = 1, QueryString = 2, TempData = 4, } and i ...

how to Ignore definitions (VS2008)

Hi, i have some sourcecode that I want to compile with VS2008 but there are many errors i have to fix. Now there are some Enums like: enum { BACKGROUND = 0x00000001, WEAPON = 0x00000002, TRANSPARENT = 0x00000004 } The problem is that TRANSPARENT is defined as: #define TRANSPARENT 1 in WinGDI.h That will cause a comp...

How can I validate enum types as Perl subroutine arguments?

Building off Does Perl have an enumeration type?, how can I perform dynamic type checking (or static type checking if use strict is able to do so) that my subroutine argument is getting the right type of enum? package Phone::Type; use constant { HOME => 'Home', WORK => 'Work', }; package main; sub fun { my ($my_phone_type...