What is value__ defined in Enum in C #

What could be value__

?

value__
MSN
ICQ
YahooChat
GoogleTalk

      

The code I ran is simple:

namespace EnumReflection
{
    enum Messengers
    {
      MSN,
      ICQ,
      YahooChat,
      GoogleTalk
    }

  class Program
  {
    static void Main(string[] args)
    {
      FieldInfo[] fields = typeof(Messengers).GetFields();

      foreach (var field in fields)
      {
        Console.WriteLine(field.Name);
      }

      Console.ReadLine();
    }
  }
}

      

+3


source to share


1 answer


You can find more here . The poster even has some sample code that should help you fix the problem ... just paste in BindingFlags.Public | BindingFlags.Static between GetFields () brackets.



Using reflection, I decided that I would win the upper hand and take control of my listing problems. Unfortunately, calling GetFields on type enum adds an extra entry named value__ to the returned list. After looking at decompiling the Enum, I found that value__ is just a special instance field used by the enum to store the value of the selected item. I also noticed that the actual members of the enum are indeed marked as static. Thus, to work around this issue, all you have to do is call GetFields with BindingFlags set only to get public static fields

+5


source







All Articles