简体   繁体   中英

Getting and Setting an Enum in C#

When I try the code below, I get a message that "the name C does not exist in the current context." What am I missing here? I would like the position part in the dictionary to behave just like the other variables, but I've been having trouble using the enum. Thanks!

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 });

        }

You're missing the enum's name pos .

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

它应显示为:

position = pos.C

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM