大写问题 C#

eArt 2008-03-17 10:53:12
public static void Main(string[] args)
{
int i;
string u;
bool x = true;
while(x)
{
Console.WriteLine("请输入等级");
Console.WriteLine("输入Q退出");

i=Convert.ToInt32(Console.ReadLine()); ————》这个地方;
u=Console.ReadLine();
if(u.ToUpper()=="q") ——————》 这个地方;
{
x=false;
}

M n = new M();
n.Money(i);
}


上面的代码有点问题,因为要验证的是数字 和 字母, 不知用一个变量是否能完成,如何完成?
另外,如何把用户输入的小写也转换成大写。大写也不变。
...全文
105 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
eArt 2008-03-17
  • 打赏
  • 举报
回复
public static void Main(string[] args)
{
int i;
string u;
bool x = true;
while(x)
{
Console.WriteLine("请输入等级");
Console.WriteLine("输入Q退出");

i=Convert.ToInt32(Console.ReadLine());
u=Console.ReadLine();
u.ToUpper();
if(u=="Q")
{
x=false;
}

M n = new M();
n.Money(i);
}
eArt 2008-03-17
  • 打赏
  • 举报
回复
调试器抛出异常System.FormatException:
Input string was not in a correct format.

StringToNumber()
ParseInt32()
ToInt32()
Main() - d:\My Documents\SharpDevelop Projects\xy\Program.cs:31,4


依旧有异常
timesclock 2008-03-17
  • 打赏
  • 举报
回复
楼上正解
virusswb 2008-03-17
  • 打赏
  • 举报
回复
string s = Console.ReadLine();
s.ToUpper();
TNT_1st_excellence 2008-03-17
  • 打赏
  • 举报
回复
        static void Main(string[] args)
{
int i;
string u;
bool x = true;
while (x)
{
Console.WriteLine("请输入等级");
Console.WriteLine("输入Q退出");

u = Console.ReadLine();
u.ToUpper();
if (u == "Q")
{
x = false;
}
else
{

try
{
i = Convert.ToInt32(Console.ReadLine());
M n = new M();
n.Money(i);

}
catch (Exception ex1 )
{
Console.Write(ex1.ToString());
return;
}

}

}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧