【发布时间】:2012-10-16 21:52:28
【问题描述】:
我很好奇是否有一种方法可以循环同一字符串变量的多个条目?基本上,我想将玩家姓名的多个条目打印到 For 循环中,但是我脑子有问题,我很难理解如何扩展我迄今为止编写的简单代码段-循环。
class Program
{
static void Main(string[] args)
{
string choice = "y";
string player_name = "";
while (choice == "y")
{
Console.WriteLine("Enter the players name: ");
player_name = Console.ReadLine();
Console.WriteLine("Would you like to enter another player? y/n");
choice = Console.ReadLine();
}
Console.WriteLine(player_name);
Console.ReadLine();
}
}
【问题讨论】:
-
将 WriteLine(player_name) 放入 while 循环不起作用?
标签: c# for-loop while-loop