Quantcast
Channel: Cinchoo » String
Viewing all articles
Browse latest Browse all 10

Cinchoo – Enum.ToDescription(), Extension Method

$
0
0

In this section, I’ll talk about ToDescription<T> extension method. This method used get enum description from enum value.

1. Add reference to Cinchoo.Core.ExtensionMethods.dll assembly

2. Namespace System

Sample:

public enum Color
{
    [Description("Red Color")]
    Red,
    [Description("Green Color")]
    Green,
    [Description("Yellow Color")]
    Yellow
}

static void Main(string[] args)
{
    Console.Write("Description of 'Color.Green' enum value is: ");
    Console.WriteLine(Color.Green.ToDescription());
}

When you run the above code, the output will be

Description of 'Color.Green' enum value is: Green Color
Press any key to continue . . .

Happy coding!!!



Viewing all articles
Browse latest Browse all 10

Trending Articles