Why does Enum.GetValues() return names when using “var”?

前端 未结 7 1048
囚心锁ツ
囚心锁ツ 2021-01-17 07:44

Can anyone explain this?

alt text http://www.deviantsart.com/upload/g4knqc.png

using System;

namespace TestEnum2342394834
{
    class Program
    {
         


        
7条回答
  •  生来不讨喜
    2021-01-17 08:05

    The var value is actually an enum value (of type ReportStatus), so you see the standard behaviour of enumValue.ToString() - it's name.

    EDIT:
    When you do a Console.WriteLine(value.GetType()) you will see that it really is a 'ReportStatus', although it's boxed in a plain Object.

提交回复
热议问题