user2548227
user2548227

Reputation: 29

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

        }

Upvotes: 0

Views: 130

Answers (2)

Damon
Damon

Reputation: 3012

It should read:

position = pos.C

Upvotes: 2

lc.
lc.

Reputation: 116438

You're missing the enum's name pos.

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

Upvotes: 6

Related Questions