tags:

views:

51

answers:

1

Here's the class:

namespace TomeOfNewerth_WPF_
{
    class Hero
    {
        public string faction;
        public string name;
        public HeroType herotype;

        public enum HeroType
        {
            Agility,
            Strength,
            Intelligence
        }
    }
}

Now in another class, just for testing I'm tring to instance the Hero class, and set the herotype property, like so:

namespace TomeOfNewerth_WPF_
{
    class Spell
    {
        Hero x = new Hero();

        public void lol()
        {
            x.herotype = x.; //How can I set it?
        }
    }
}

The only reason I created the herotype property from an Enum was to make the application more robust and not rely on literal strings.

Thanks for the help.

+1  A: 

x.herotype = HeroType.Agility; is normally the code to set it. You will need to move HeroType outside of the class for this to work.

For what it's worth, this might be better off in a constructor, and you should look into exposing class information through Properties instead of public member variables.

Michael Greene
I can't call HeroType enum from my spell class or from any other class for that matter. That's where I'm having trouble.
Sergio Tapia
Hero.HeroType.Agility - nested class
Aviad P.
Thanks Aviad. Works.
Sergio Tapia
Yes, you could use `Hero.HeroType.Agility` but I'd personally recommend not nesting the class and moving the `HeroType` enum out into the namespace if other classes are intended to use it.
Michael Greene
Wow, didn't know you could do that with an Enum. So much to learn, so little time.
Sergio Tapia