enums

Trouble Serializing Enum in .NET

I have an elementary stumper using serialization in an ASP.NET 2.0 application on a C# class containing an enum property. It's my understanding that serialization of enumerations is supported if they map to integers. So, I can't figure out why I'm having this problem serializing/deserializing my enum. My Code: [Serializable] public c...

Use variadic functions in C89 without passing number of arguments or a final argument?

Let's say I have a variadic function foo(int tmp, ...), when calling foo function I need to know how many arguments there are. I'm aware of two ways of finding out how many arguments there are: Use a final argument when calling foo, like -1, so your function call will be like this: foo(tmp, 1, 2, 9, -1) and when you are inside foo and...

Check 3 enum values in one go?

Hello, I have an enum which looks like this: enum myEnum { field1 = 11, field2 = 12, field3 = 33 }; In my code I need to say that field1 is 1,field2 is 2 and field3 is 3 according to a variable I have. This variable is either 1 or 2 or 3; it's an int. Can I write that in one line? Something like the following, but shorter....

Passing an enum as a parameter in a method?

Hey, I have an abstract class Medium, where one of the datamembers is an enum. private Taal talenOndertiteling[]; public enum Taal { NEDERLANDS, FRANS, DUITS, ENGELS, SPAANS, ITALIAANS } public Taal[] getTalenOndertiteling() { return talenOndertiteling; } public void setTalenOndertiteling(Taal[] talenOndertiteling) { this....

standards compliant way to typedef my enums

How can I get rid of the warning, without explicitly scoping the enum properly? The standards-compliant code would be to compare against foo::bar::mUpload (see here), but the explicit scopes are really long and make the darn thing unreadable. maybe there's another way that doesn't use typedef? i don't want to modify the enum--i didn't w...

Why can I not "see" this enum extension method?

Why cannot I see this enum extension method? (I think I'm going crazy). File1.cs namespace Ns1 { public enum Website : int { Website1 = 0, Website2 } } File2.cs using Ns1; namespace Ns2 { public class MyType : RequestHandler<Request, Response> { public override Res...

Passing enum values to a function in PowerShell

I have a function accepting an enum value as parameter. As an example, consider something like: (PS) > function IsItFriday([System.DayOfWeek] $dayOfWeek) { if($dayOfWeek -eq [System.DayOfWeek]::Friday) { "yes" } else { "no" } } Now, if I invoke it like this, everything is fine: (PS) > $m = [System.DayOfW...

Getting java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd

Hi All, I need a serious help in this issue. May be its very basic, but, I am not able to figure it out. I have a session EJB with one method which returns an enum array, i.e. BlndItmTmMthd array. When, I call the method in the client side, it gives me a ClassCastException. java.lang.ClassCastException: [Ljava.lang.Object; cannot be cas...

How do you import an enum into a different namespace in C++?

I have an enum in a namespace and I'd like to use it as if it were in a different namespace. Intuitively, I figured I could use 'using' or 'typedef' to accomplish this, but neither actually work. Code snippet to prove it, tested on GCC and Sun CC: namespace foo { enum bar { A }; } namespace buzz { // Which of these two methods I ...

How to enumerate a range of numbers starting at 1

I am using Python 2.5, I want an enumeration like so (starting at 1 instead of 0): [(1, 2000), (2, 2001), (3, 2002), (4, 2003), (5, 2004)] I know in Python 2.6 you can do: h = enumerate(range(2000, 2005), 1) to give the above result but in python2.5 you cannot... Using python2.5: >>> h = enumerate(range(2000, 2005)) >>> [x for x in ...

Check if wind direction is within a specified range

I am representing wind directions using integer values (an Enum) ranging from 0 for North, through to 15 for North-North-West. I need to check if a given wind direction (integer value between 0 and 15) is within a certain range. I specify my WindDirectionFrom value first moving clockwise to WindDirectionTo to specify the range of allowa...

How do I comment a publicly visible type Enum?

How do I comment this Enum so that the warning does not appear? Yes I realize that comments are unnecessary, but if commenting is easy and it resolves the warnings then I'd like to do it. Warnings that appear: Missing XML comment for publicly visible type or member /// <summary> /// Conditional statements /// </summary> public enum Co...

Too many lookup tables

Hello, What are the adverse effects of having too many lookup tables in the database? I have to incorportate too many Enumerations, based on the applications. What would experts advice? ...

Class for representing a card in Java?

I'm making a blackjack program in Java, and I was starting to write the class declaration for an object Card. Will this be sufficient, or are there some methods I should have that I'm glossing over? public class Card { public int suit; //Value 1-4 to represent suit public int value; //Value 1-13 to represent value (i.e. 2, J) ...

Get enum name when value is known

I have an enum that has different colors in it. I would like to pass some function an int and have it return the color name that is in the enum in that position. What's the way to do this? ...

Enum typed properties in Entity Framework entities?

Is there a way I can map generated entities to enum? And what I mean is simple: class Person { RelationshipStaus RelationshipStatus { get; set; } } enum RelationshipStatus : byte { Single, Married, Divorced } The property RelationshipStatus in the DB is a simple byte, I want that in my project it should be an enum. ...

C++: Print out enum value as text

If i have an enum like this enum Errors {ErrorA=0, ErrorB, ErrorC}; Then i want to print out to console Errors anError = ErrorA; cout<<anError;/// 0 will be printed but what i want is the text "ErrorA", can i do it without using if/switch? And what is your solution for this? ...

How to use enum within a struct in ANSI C?

Following code has to be used in the main-function, but I don't know how it is used. struct SomeItem { enum {MOVIE, MUSIC} itemType; union { struct Movie* movie; struct Music* music; }; }; this struct is used in a dynamic linked list with previous/item/next pointer, but I don't know how you can set the enum...

What is wrong the Java enum definition

I defined public enum ABC in ABC.java and then compiled it to ABC.class. In another XYZ.java, I use private ABC _abc. XYZ and ABC are in some package. But it tells cannot find symbol class ABC. What is wrong? package teacherII; public enum Semester { Fall1999, Spring2000, Fall2000, Spring2001, Fall2001, Spring2002,...

Alternative to "char" enum

I have a database which needs a status column updating to a single char status code ('E' or 'U'). I'd like to use an enum for updating this field through my API to ensure the possible values are restricted correctly. Obviously enums can't be of char type. What might be be a good alternative method? And no, I can't change the database s...