Can my enums have friendly names? [duplicate]

You could use the Description attribute, as Yuriy suggested. The following extension method makes it easy to get the description for a given value of the enum: public static string GetDescription(this Enum value) { Type type = value.GetType(); string name = Enum.GetName(type, value); if (name != null) { FieldInfo field = type.GetField(name); if (field != … Read more

SQL query to get all values a enum can have

If you want an array: SELECT enum_range(NULL::myenum) If you want a separate record for each item in the enum: SELECT unnest(enum_range(NULL::myenum)) Additional Information This solution works as expected even if your enum is not in the default schema. For example, replace myenum with myschema.myenum. The data type of the returned records in the above query … Read more

How can I lookup a Java enum from its String value?

Use the valueOf method which is automatically created for each Enum. Verbosity.valueOf(“BRIEF”) == Verbosity.BRIEF For arbitrary values start with: public static Verbosity findByAbbr(String abbr){ for(Verbosity v : values()){ if( v.abbr().equals(abbr)){ return v; } } return null; } Only move on later to Map implementation if your profiler tells you to. I know it’s iterating over … Read more

Enums in Javascript with ES6

Is there a problem with this formulation? I don’t see any. Is there a better way? I’d collapse the two statements into one: const Colors = Object.freeze({ RED: Symbol(“red”), BLUE: Symbol(“blue”), GREEN: Symbol(“green”) }); If you don’t like the boilerplate, like the repeated Symbol calls, you can of course also write a helper function makeEnum … Read more

Convert Enum to String

As of C#6 the best way to get the name of an enum is the new nameof operator: nameof(MyEnum.EnumValue); // Ouputs > “EnumValue” This works at compile time, with the enum being replaced by the string in the compiled result, which in turn means this is the fastest way possible. Any use of enum names … Read more

Can I set enum start value in Java?

Java enums are not like C or C++ enums, which are really just labels for integers. Java enums are implemented more like classes – and they can even have multiple attributes. public enum Ids { OPEN(100), CLOSE(200); private final int id; Ids(int id) { this.id = id; } public int getValue() { return id; } … Read more

Methods inside enum in C#

You can write extension methods for enum types: enum Stuff { Thing1, Thing2 } static class StuffMethods { public static String GetString(this Stuff s1) { switch (s1) { case Stuff.Thing1: return “Yeah!”; case Stuff.Thing2: return “Okay!”; default: return “What?!”; } } } class Program { static void Main(string[] args) { Stuff thing = Stuff.Thing1; String … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)