C# numeric enum value as string

You should just be able to use the overloads of Enums ToString method to give it a format string, this will print out the value of the enum as a string. public static class Program { static void Main(string[] args) { var val = Urgency.High; Console.WriteLine(val.ToString(“D”)); } } public enum Urgency { VeryHigh = 1, … Read more

Return different type of data from a method in java?

I create various return types using enum. It doesn’t defined automatically. That implementation look like factory pattern. public enum SmartReturn { IntegerType, DoubleType; @SuppressWarnings(“unchecked”) public <T> T comeback(String value) { switch (this) { case IntegerType: return (T) Integer.valueOf(value); case DoubleType: return (T) Double.valueOf(value); default: return null; } } } Unit Test: public class MultipleReturnTypeTest { … Read more