CSharp - List enum underline value

Introduction

The following code uses Enum type GetValues() method to get the underline value for an enum type.

Demo

using System;

class Program/*w  ww.  ja  v a2s.  c om*/
{
    enum Values { val1, val2 = 100, val3 = 50, val4, val5 };
    static void Main(string[] args)
    {
        foreach (Values v in Enum.GetValues(typeof(Values)))
        {
            Console.WriteLine("{0} is storing {1}", v, (int)v);
        }
    }
}

Result

Related Example