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);
}上面的代码有点问题,因为要验证的是数字 和 字母, 不知用一个变量是否能完成,如何完成?
另外,如何把用户输入的小写也转换成大写。大写也不变。 

解决方案 »

  1.   

    string s = Console.ReadLine();
                s.ToUpper();
      

  2.   

    调试器抛出异常System.FormatException:
    Input string was not in a correct format.StringToNumber()
    ParseInt32()
    ToInt32()
    Main() - d:\My Documents\SharpDevelop Projects\xy\Program.cs:31,4
    依旧有异常
      

  3.   

    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);
    }
      

  4.   

            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;
                        }                }            }