谁帮我改一下这段C#代码呀?谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/26 00:22:08
要求:输入任何字符进入程序,输入END退出,进入程序后输入要查询ASCII值的字符,查询后输入Y继续查询,N退出程序。我写的不对,麻烦帮我改一下,谢谢!

using System;
class s
{
static void Main()
{
int x = 0;
Console.WriteLine("进入程序请输入任何字符,退出请输入“END” ^_^");
string a = "";
while (a != "END")
{
a = Console.ReadLine();
while (1 == 1)
{
Console.WriteLine("\n请输入要查询ASCII值的字符:");
x = Console.Read();
Console.WriteLine("该字符的ASCII值为:{0}", x);

break;
}

}

}

}

你的x是int型的.
x=console.Read();是被赋字符串值的,改成
x = Convert.Tostring(Console.ReadLine());
第二个while里面放个true吧,1==1好别扭啊!
查询后你还要询问是否继续查询所以第二个while里还要作个判断
char c;
while(1==1)
{
///你原来的代码
c = Console.Read();
if(c=='n')
{
break;
}
else if(c=='y')
{
}
else
{
Console.WriteLine("输入错误");
}
}