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


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

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

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s