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

前端 未结 7 1129
囚心锁ツ
囚心锁ツ 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:04

    An enumeration type is distinct from an integer. In your sample, var does not evaluate to int, it evaluates to the enumeration type. You would get the same output if you had used the enumeration type itself.

    Enumeration types output the name when printed, not their value.

提交回复
热议问题