Quantcast
Viewing latest article 6
Browse Latest Browse All 10

Cinchoo – Enum.ToDescription(), Extension Method

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!!!


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 6
Browse Latest Browse All 10

Trending Articles