In java <1.5, constants would be implemented like this
public class MyClass {
public static int VERTICAL = 0;
public static int HORIZONTAL = 1;
private int orientation;
public MyClass(int orientation) {
this.orientation = orientation;
}
...
and you would use it like this:
MyClass myClass = new MyClass(My...
In the external code that I am using there is enum:
enum En {VALUE_A, VALUE_B, VALUE_C};
In another external code that I am using there are 3 #define directives:
#define ValA 5
#define ValB 6
#define ValC 7
Many times I have int X which is equal to ValA or ValB or ValC, and I have to cast it to the corresponding value of En (ValA...
Hi folks,
i've got the following linq2sql query, and i'm setting the result to a POCO. One of my POCO properties is an enumeration.
public IQueryable<Models.Achievement> GetAchievements()
{
return from a in _sqlDatabase.Achievements
select new Models.Achievement
{
// Note: ToEnum is an extension ...
When we serialize an enum from C# to SQL Server we use a NCHAR(3) datatype with mnemonic values for each value of the enum.
That way we can easily read a SELECT qry.
How do you save enum to your database?
What datatype do you use?
...
enum MyEnum {
A( 1, 2, 3, 4),
B(1, 2),
C(4, 5, 8, 8, 9);
private MyEnum( int firstInt, int... otherInts ) {
// do something with arguments, perhaps initialize a List
}
}
Are there any problems with this? Any reasons not to do it?
...
I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.
...
Hey!
I am having some issues with using the OrderBy extension method on a LINQ query when it is operating on an enum type. I have created a regular DataContext using visual studio by simply dragging and dropping everything onto the designer. I have then created seperate entity models, which are simply POCO's, and I have used a repositor...
Here is the basic situation.
Public Class MyEnumClass(of T)
Public MyValue as T
End Class
This is vast oversimplification of the actual class, but basically I know that T is an enumeration (if it is not then there will be many other problems, and is a logical error made by the programmer)
Basically I want to get the underlying int...
After watching: The Clean Code Talks -- Inheritance, Polymorphism, & Testing
I checked my code and noticed a few switch statements can be refactored into polymorphism, but I also noticed I only used switch statements with enums. Does this mean enums are "evil" in OO-design and should be eliminated with polymorphism?
...
I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about...
I've tried searching the internet for this, but using the "~" in a search isn't working for me so well and I didn't find anything on MSDN either (not to say it isn't there)
I saw this snippet of code recently, what ...
I am trying to design an object model (for C#), and can't work out the best way to store the data. I'll try to use a simple example to illustrate this!
I have an object "pet", which could be one of, "cat", "dog" etc. So I have created an "pet" class with a "petType" enum to store this.
Now this is where it gets tricky. If an "pet" is a...
I've got an enum like this:
public enum MyLovelyEnum
{
FirstSelection,
TheOtherSelection,
YetAnotherOne
};
I got a property in my DataContext:
public MyLovelyEnum VeryLovelyEnum { get; set; }
And I got three RadioButtons in my WPF client.
<RadioButton Margin="3">First Selection</RadioButton>
<RadioButton Margin="3">The Other...
I have a Enum for example...
public enum TypeIdentifier {
NotSet = 0,
Type1= 1,
Type2= 2,
Type3= 3,
Type4= 4,
Type5= 5
}
public class CommonObject
{
TypeIdentifier myTypeIdentifier {get; set;}
}
I have a WPF UserControl that has a generalized object binding.I have a c...
I have a Linq to Entities query like this one:
var results = from r in entities.MachineRevision
where r.Machine.IdMachine == pIdMachine
&& r.Category == (int)pCategory
select r;
Usually, I use the code below to check if some results are returned:
if (results.Count() > 0)
{
return new o...
I have this enum:
enum ButtonState {
BUTTON_NORMAL = 0,
BUTTON_PRESSED = 1,
BUTTON_CLICKED = 2
};
const u8 NUM_BUTTON_STATES = 3;
In my Button class I have member variables ButtonState state; and ButtonColors colors[NUM_BUTTON_STATES];. When drawing the button, I use colors[state] to get the colours for whatever state the...
Are all Enum enumerations constants? Do they get converted to their value at compile-time, or at run-time?
...
Would there be difference in speed between
if (myInt == CONST_STATE1)
and
if (myEnum == myENUM.State1)
in c#?
...
Is there a way in Java to declare an enumeration whose values can be used together? For example:
enum FileAccess { Read, Write, ReadWrite }
Is it possible to define ReadWrite as Read | Write (or anything that would yield the same result)?
...
Hi
I am modeling a class diagram. An attribute of a class is an enumeration. How do i model this? Normally you do something like this: - name : string But how to do this with an enum?
Thnx in advance :)
...
i created a wpf custom control with a dependency property of an enum type.
i want the user of that control when editing the xaml in vs to see the optional values of the enum in the intellisense window.
does anyone know how it can be done?
...