I am completely new to C #, WPF and OOP, and am facing a problem with objects.
I am creating a small RPG and have a Player class that has a constructor that automatically assigns default values to the object that was created.
So, with WPF / XAML, I created a button associated with a function; when I press the button, this function will be executed:
private void NewGameClick(object sender, RoutedEventArgs e)
{
Player hero = new Player("Tristan");
MessageBox.Show("The character " + hero.Name + " has been created.");
}
The character name is actually displayed in the message field, but I cannot use the "hero" object created by the function in the rest of my code. Is it because the object is deleted at the end of the function? Is there a way to save this object and use it outside of this function?
Thank!
source
share