我试图在主类中设置一个字符串,并将其发送给我的名称类,然后稍后在主类的另一个方法中使用它。 这就是我所拥有的。如何在一个类中创建一个字符串并在另一个类中使用它
我对编码相当陌生,今年刚上课。任何帮助。
我只是想做一个简单的冒险游戏。
提前致谢!
class Player
{
public string playerName { get; set; }
}
class MainClass
{
public static void nameSelection()
{
Player player = new Player();
Console.Clear();
Console.WriteLine ("Let's start off simple adventurer, what is your name?");
player.playerName = Console.ReadLine();
Console.Clear();
Console.WriteLine ("Are you sure {0} is your name? Type 1 for yes and 2 for no", player.playerName);
string confirm = Console.ReadLine();
if (confirm == "1") {
Console.Clear();
Console.WriteLine ("Okay {0}, here we go!", player.playerName);
Console.ReadLine();
}
else if (confirm == "2") {
Console.Clear();
nameSelection();
}
else
{
Console.Clear();
nameSelection();
}
}
public static void classselsction()
{
Console.ReadLine();
Console.WriteLine ("As you get to the end of the hallway you see a shadow.");
Console.ReadLine();
Console.WriteLine("Hello {0}, I see you have managed to escape from your cell. " +
"You have proven yourself quite worthey.", player.playerName);
Console.ReadLine();
}
}
嗨,欢迎来到SO。您是否收到错误,您得到的结果与您的期望不符? – miltonb