我又遇到了一个错误,我不想打扰任何人,但我在这段代码上遇到了错误:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Input_Program
{
class Program
{
private static void Main()
{
char Y;
char N;
Console.WriteLine("Welcome to my bool program!");
Console.WriteLine("Input a NON capital y or n when told to.");
if(Y == 'y')
{
Console.WriteLine("Thank you,Please wait.....");
}
}
}
}
感谢您的回答!
最佳答案
您的变量 char Y
在使用前未初始化。声明的时候尽量给一个默认值。
编辑 看起来你想让用户输入一些东西,然后把它赋值给变量 Y。试试:
Y = Console.ReadKey().KeyChar;
关于c# - 错误 2 使用未分配的局部变量 'Y',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5400485/