【问题标题】:Getting and Setting an Enum in C#在 C# 中获取和设置枚举
【发布时间】:2013-08-01 18:09:26
【问题描述】:

当我尝试下面的代码时,我收到一条消息“名称 C 在当前上下文中不存在”。我在这里想念什么?我希望字典中的位置部分的行为与其他变量一样,但我在使用枚举时遇到了麻烦。谢谢!

class stats
    {
        enum pos { fiB, seB, SS, thB, LF, CF, RF, C, DH, SP, RP };
        public double age {get; set;}
        public pos position{get; set;}
        public double ovalue{get; set;}
        public double dvalue{get; set;}
    }
    public partial class playerdictionary:stats
    {
        public playerdictionary()
        {
            var dict = new Dictionary<string, stats>();
            dict.Add("AG", new stats { age = 24, position=C, ovalue = 0, dvalue = 4.2 });

        }

【问题讨论】:

  • 你试过pos.C吗?

标签: c# enums get set


【解决方案1】:

您缺少枚举的名称 pos

position = pos.C;
//         ^^^^

【讨论】:

    【解决方案2】:

    应该是:

    position = pos.C
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 2016-11-30
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多