Is there a way how to return full enum by property? Here is example of what I want to do:  // MyEnums.cs public enum Languages {     cs = 0,     pl = 1,     en = 2,     de = 3, }  // General.cs public static MyEnums.Languages Languages {     get     {         return MyEnums.Languages;     } }
1080
How can you enumerate an enum in C#?  E.g. the following code does not compile:  public enum Suit {     Spades,     Hearts,     Clubs,     Diamonds }  public void EnumerateAllSuitsDemoMethod() {     foreach (Suit suit in Suit)     {         DoSomething(suit);     } }   And it gives the following compile-time error:     'Suit' is a 'type' but is used like a 'variable'   It fails on the Suit keyword, the second one.
102377
Assuming there are 5 items in the settings file (MySetting1 to MySetting5), why does PropertyValues have 0 items while Properties has the correct number?   Console.WriteLine( Properties.Settings.Default.PropertyValues.Count); // Displays 0 Console.WriteLine( Properties.Settings.Default.Properties.Count);     // Displays 5
81127
Would the following make the objects fulfill all charasteristics that enums have in JavaScript? Something like: my.namespace.ColorEnum = {     RED : 0,     GREEN : 1,     BLUE : 2 }  // later on  if(currentColor == my.namespace.ColorEnum.RED) {    // whatever }  Or is there some other way I can do this?
12823
In .NET, what is the difference between String.Empty and "", and are they interchangable, or is there some underlying reference or Localization issues around equality that String.Empty will ensure are not a problem?
26601
Is there a Java equivalent for  in C#/.NET? Or any code to accomplish this?  This static method combines one or more strings into a path.
30132
What I want to do is something like this: I have enums with combined flagged values.  public static class EnumExtension {     public static bool IsSet&lt;T&gt;( this T input, T matchTo )          where T:enum //the constraint I want that doesn't exist in C#3     {             return (input &amp; matchTo) != 0;     } }   So then I could do:  MyEnum tester = MyEnum.FlagA | MyEnum.FlagB  if( tester.IsSet( MyEnum.FlagA ) )     //act on flag a   Unfortunately, C#'s generic where constraints have no enum restriction, only class and struct. C# doesn't see enums as structs (even though they are value types) so I can't add extension types like this.  Does anyone know a workaround?
4407
I know this rather goes against the idea of enums, but is it possible to extend enums in C#/Java?  I mean "extend" in both the sense of adding new values to an enum, but also in the OO sense of inheriting from an existing enum.    I assume it's not possible in Java, as it only got them fairly recently (Java 5?).  C# seems more forgiving of people that want to do crazy things, though, so I thought it might be possible some way.  Presumably it could be hacked up via reflection (not that you'd every actually use that method)?  I'm not necessarily interested in implementing any given method, it just provoked my curiosity when it occurred to me :-)
65369
I have an enum construct like this:  public enum EnumDisplayStatus {     None    = 1,     Visible = 2,     Hidden  = 3,     MarkedForDeletion = 4 }   In my database, the enumerations are referenced by value. My question is, how can I turn the number representation of the enum back to the string name.   For example, given 2 the result should be Visible.
20257
Are C++ enums signed or unsigned? And by extension is it safe to validate an input by checking that it is &lt;= your max value, and leave out >= your min value (assuming you started at 0 and incremented by 1)?
17522
I've been programming in Java for a while and just got thrown onto a project that's written entirely in C#.  I'm trying to come up to speed in C#, and noticed enums used in several places in my new project, but at first glance, C#'s enums seem to be more simplistic than the Java 1.5+ implementation.  Can anyone enumerate the differences between C# and Java enums, and how to overcome the differences?  (I don't want to start a language flame war, I just want to know how to do some things in C# that I used to do in Java).  For example, could someone post a C# counterpart to Sun's famous Planet enum example?  public enum Planet {   MERCURY (3.303e+23, 2.4397e6),   VENUS   (4.869e+24, 6.0518e6),   EARTH   (5.976e+24, 6.37814e6),   MARS    (6.421e+23, 3.3972e6),   JUPITER (1.9e+27,   7.1492e7),   SATURN  (5.688e+26, 6.0268e7),   URANUS  (8.686e+25, 2.5559e7),   NEPTUNE (1.024e+26, 2.4746e7),   PLUTO   (1.27e+22,  1.137e6);    private final double mass;   // in kilograms   private final double radius; // in meters   Planet(double mass, double radius) {       this.mass = mass;       this.radius = radius;   }   public double mass()   { return mass; }   public double radius() { return radius; }    // universal gravitational constant  (m3 kg-1 s-2)   public static final double G = 6.67300E-11;    public double surfaceGravity() {       return G * mass / (radius * radius);   }   public double surfaceWeight(double otherMass) {       return otherMass * surfaceGravity();   } }  // Example usage (slight modification of Sun's example): public static void main(String[] args) {     Planet pEarth = Planet.EARTH;     double earthRadius = pEarth.radius(); // Just threw it in to show usage      // Argument passed in is earth Weight.  Calculate weight on each planet:     double earthWeight = Double.parseDouble(args[0]);     double mass = earthWeight/pEarth.surfaceGravity();     for (Planet p : Planet.values())        System.out.printf("Your weight on %s is %f%n",                          p, p.surfaceWeight(mass)); }  // Example output: $ java Planet 175 Your weight on MERCURY is 66.107583 Your weight on VENUS is 158.374842 [etc ...]
31492
How do I enumerate the properties of a JavaScript object?  I actually want to list all the defined variables and their values, but I've learned that defining a variable actually creates a property of the window object.
9571
I realize that it seems to be a duplicate of  but my question has a slight difference (from my point of view):  Once I know that   I will not use my class with "techniques that only works on properties" and  I will not use validation code in the getter/setter.   Is there any difference (except the style/future development ones), like some type of control in setting the property?  Is there any additional difference between:  public string MyString { get; set; }   and   public string myString;   (I am aware that, that the first version requires C# 3.0 or above and that the compiler does create the private fields.)
49609
I have a bunch of enum types in some library header files that I'm using, and I want to have a way of converting enum values to user strings - and vice-versa.   RTTI won't do it for me, because the 'user strings' need to be a bit more readable than the enumerations.  A brute force solution would be a bunch of functions like this, but I feel that's a bit too C-like.  enum MyEnum {VAL1, VAL2,VAL3};  String getStringFromEnum(MyEnum e) {   switch e   {   case VAL1: return "Value 1";   case VAL2: return "Value 2";   case VAL1: return "Value 3";   default: throw Exception("Bad MyEnum");   } }   I have a gut feeling that there's an elegant solution using templates, but I can't quite get my head round it yet.  UPDATE: Thanks for suggestions - I should have made clear that the enums are defined in a third-party library header, so I don't want to have to change the definition of them.  My gut feeling now is to avoid templates and do something like this:  char * MyGetValue(int v, char *tmp); // implementation is trivial  #define ENUM_MAP(type, strings) char * getStringValue(const type &amp;T) \  { \  return MyGetValue((int)T, strings); \  }  ; enum eee {AA,BB,CC}; - exists in library header file  ; enum fff {DD,GG,HH};   ENUM_MAP(eee,"AA|BB|CC") ENUM_MAP(fff,"DD|GG|HH")  // To use...      eee e;     fff f;     std::cout&lt;&lt; getStringValue(e);     std::cout&lt;&lt; getStringValue(f);
57892
Is it possible to overload the null-coalescing operator for a class in C#?    Say for example I want to return a default value if an instance is null and return the instance if it's not. The code would look like something like this:     return instance ?? new MyClass("Default");     But what if I would like to use the null-coalescing operator to also check if the MyClass.MyValue is set?
108044
I don't think I fundamentally understand what an enum is, and when to use it.    For example:  typedef enum {     kCircle,     kRectangle,     kOblateSpheroid } ShapeType;   What is really being declared here?
19677
What's the best way to implement the enum idiom in Ruby? I'm looking for something which I can use (almost) like the Java/C# enums.
527
From time to time I see an enum like the following:  [Flags] public enum Options  {     None    = 0,     Option1 = 1,     Option2 = 2,     Option3 = 4,     Option4 = 8 }   I don't understand what exactly the [Flags] attribute does.  Anyone have a good explanation or example they could post?