When I try to SET an attribute from another class to another it doesn't allow me to
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 clas开发者_StackOverflow中文版s, 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.
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.
精彩评论