gpt4 book ai didi

c# - 将变量传递给c#中的不同方法

转载 作者:行者123 更新时间:2023-11-30 19:55:14 24 4
gpt4 key购买 nike

<分区>

我只是想知道您是否可以快速回答我的问题。我正在做一个文字冒险游戏,我试图让玩家在主要区域中设置他们的名字,并将其存储到一个变量中并在其他方法中使用它。

public static void Main(string[] args)
{
//intro

System.Console.WriteLine("Welcome to TextAdventure!");
System.Console.WriteLine("This is an entry level program made by JussaPeak");
System.Console.WriteLine("commands will be noted in the text by (). enter an applicable choice.");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine("Please enter your name:");
string name = Convert.ToString(Console.ReadLine());
System.Console.WriteLine(" ");
System.Console.WriteLine("Hello, {0}. You are about to embark on a lackluster journey of my first text adventure. i hope you enjoy!", name);
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");

StartingArea();
}
public static void GypsyConvo2()
{
Console.WriteLine("You decide to stay and hear her out");
Console.ReadKey();
Console.WriteLine("{0}: Who is this person?", name);
Console.ReadKey();
Console.WriteLine("Gypsy: He is the shapeshifting king from the mountain in the west. His land is untouched by ours.");
Console.WriteLine("'I believe he is plotting to take our land...'");
Console.ReadKey();
Console.WriteLine(" ");
Console.WriteLine("{0}: and what am i to do about that?", name);
Console.ReadKey();
Console.WriteLine("Gypsy: You must warn the queen. i've found an old sewer maintainence that can lead near the entrance to the castle itself. You'll have to find your own way from there.");


}

那么我如何才能使从 main 中的 ReadLine 赋值的变量可以在其他方法中使用而不会引发错误?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com