【发布时间】:2011-03-23 03:12:31
【问题描述】:
我又遇到了一个错误,我并不是要打扰任何人,但我在这段代码上遇到了一个错误:
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.....");
}
}
}
}
感谢您的回答!
【问题讨论】:
-
嗯... Y 从未被赋值?
-
一般规则是在声明变量时应该始终初始化变量。所以你不应该写
char Y;,而是写char Y = 'y';。 -
哦,我用 c# 获取输入,我习惯了 c++ 语法
标签: c# .net variables local-variables unassigned-variable