class Board
{
public:
enum Player {X = -1, O, E};
bool win(Player P); // A function that returns true if Player P has won the game, and
// false otherwise.
}; // end class board
The above is part of my header file for a Tic-Tac-Toe game. I am trying test the win function and confused on how to test i...
I'm trying to understand DataForm as implemented in the November 2009 toolkit and I can't work out how to bind a ComboBox to an enum. Does anyone know how the DataForm does this automatically?
Background
First I created a class and an Enum, following this article and allowed the DataForm to generate the fields. The DataForm generated...
I'm looking for a class like EnumMap, except for enum type values (ie. EnumValueMap<K,V extends Enum<V>>).
http://java.sun.com/javase/6/docs/api/java/util/EnumMap.html
Edit
If I was mapping, say, a few million Objects to 10 enum types, I imagined it would at least be possible to create a more memory-efficient implementation than just ...
I have an attribute in my car class called VehicleType.
Using an enum, I could list the different types of cars that exist and not allow any other type to be hard written in.
Problem is, if I have to GET the attribute from somewhere else, I will GET a numberical value, and not the string literal I saved.
What should I use here?
class...
Here's the class:
namespace TomeOfNewerth_WPF_
{
class Hero
{
public string faction;
public string name;
public HeroType herotype;
public enum HeroType
{
Agility,
Strength,
Intelligence
}
}
}
Now in another class, just for testing I'm trin...
I have an enum:
public enum Color
{
Red,
Blue,
Green,
}
Now if I read those colors as literal strings from an XML file, how can I convert it to the enum type Color.
class TestClass
{
public Color testColor = Color.Red;
}
Now when setting that attribute by using a literal string like so, I get a very harsh warning f...
Hi I am having a problem with a c# WebService, it was working fine but suddenly it stopped working, I am getting this error:
Unhandled Exception: System.InvalidOperationException: There is an error in XML document
System.InvalidOperationException: 'Big' is not a valid value for Sources
Sources is an enum, so I went to my wsdl an it was...
Hello there,
I want to expose enum attributes to WCF client application, but I can only see enum values.
Here is the enum:
public enum TemplateType
{
[EnumDescription("Property Particulars")]
[EnumValue("PropertyParticulars")]
PropertyParticulars = 1,
[EnumDescription("Short Format Lists")]
[EnumValue("...
Is there a way to "inherit" imports?
Example:
Common enum:
public enum Constant{ ONE, TWO, THREE }
Base class using this enum:
public class Base {
protected void register(Constant c, String t) {
...
}
}
Sub class needing an import to use the enum constants convenient (without enum name):
import static Constant.*; /...
I was looking for some enums options, and just spotted a missing comma after last option. Take, for instance, that DayOfWeek enum (press F12 to go to definition):
public enum DayOfWeek
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6, // note this comma...
I have an enum which is private, not to be exposed outside of the class. Is there anyway I can do a static import of that type, so that I don't have to type the enum type each time? Or is there a better way to write this? Example:
package kip.test;
import static kip.test.Test.MyEnum.*; //compile error
public class Test
{
private s...
Hi,
Would ENUM('1','2','3','4','5') be a sensible datatype for a product rating which must be between 1 and 5?
Thanks!
...
I am looking to return the following class through a web service, which includes an enum type as one of its members.
[Serializable, XmlRoot("GeoCoordinate")]
public class GeoCoordinate
{
public enum AccuracyLevel
{
Unknown = 0,
Country = 1,
Region = 2,
SubRegion = 3,
Town = 4,
Post...
Test program (.NET 2.0):
[Flags]
enum MyEnum
{
Member1 = 1,
Member2 = 2,
}
class Program
{
// Inspecting r shows "Member1 | Member2"
MyEnum r = MyEnum.Member1 | MyEnum.Member2;
// s = "Member1, Member2"
string s = r.ToString();
}
I would have expected .ToString() to return a string with the members separated b...
Does Java allow something like good ol' C or even C# in the sense that you can define an enum with fields that grow in value automatically, and start at an optionally given value?
E.g.
In C or C#:
enum Foo { A = 10, B, C, D = 5000, E, Fish };
Yields A = 10, B = 11, C = 12, D = 5000, E = 5001, Fish = 5002.
...
I know that you can't use inheritance with enums, so in my base class I want to define that the classes that implement it must return an enum of some type for a property.
Ideally, this would be like:
public abstract BaseEnum MyEnum { get; set; }
Then all the implementers would have to return some form of enum. But obviously BaseEnum ...
Is it possible to get an enum to hold 64bit values? I wrote the below and got this compile error message.
enum EnumTest { a = 0x100000000 };
error CS0266: Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
...
Follow along in my test source. What is a good way to get a value from a enum object? Must support long. I am attempting without a try/catch block.
enum ELong: long { a = 0x100000000 };
enum ENormal { a = 25 }
var l = (object) ELong.a;
var n = (object)ENormal.a;
//will cast into the correct size
int ii =...
We have legacy character codes that we want to store as numbers in a new system. To increase readibility and general understanding in the code for devs making the migration, I want to do Enums like this...
Public Enum Status As Short
Open = AscW("O")
Closed = AscW("C")
Pending = AscW("P")
EnRoute = AscW("E")
End Enum
W...
Question 1: I am playing around with EF4 and I have a model class like :
public class Candidate {
public int Id {get;set;}
public string FullName {get;set;}
public Gender Sex {get;set;}
public EducationLevel HighestDegreeType {get;set;}
}
Here Gender and EducationLevel are Enums like:
public enum Gender {Male,Female,Undisclosed}
pub...