Retrieves the name of the constant in the specified enumeration that has the specified value. - CSharp System

CSharp examples for System:Enum

Description

Retrieves the name of the constant in the specified enumeration that has the specified value.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from   w  w w  .  j a  va2 s  . c  o m*/

public class Main{
        /// <summary>
        /// Retrieves the name of the constant in the specified enumeration that has
        /// the specified value.
        /// </summary>
        /// <param name="value">The value of a particular enumerated constant in terms of its underlying
        /// type.</param>
        /// <returns>A string containing the name of the enumerated constant in <typeparamref name="TEnum"/> whose
        /// value is value; or null if no such constant is found.</returns>
        /// <exception cref="System.ArgumentNullException">value is null.</exception>
        /// <exception cref="System.ArgumentException">value is neither of type <typeparamref name="TEnum"/> nor
        /// does it have the same underlying type as <typeparamref name="TEnum"/>.</exception>
        public static string GetName(TEnum value)
        {
            return Enum.GetName(_enumType, value);
        }
}

Related Tutorials