string line = Console.ReadLine();
try
{
  int a=Int32.Parse(line.Trim());
}
catch(Exception ex)
{}

解决方案 »

  1.   

    using System;class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入第一个数");
            int a = int.Parse(Console.ReadLine()); //要类型转换
            Console.WriteLine("请输入第二个数");
            int b = int.Parse(Console.ReadLine());
            if (a < b)
            {
                Console.WriteLine(b);
            }
            else
            {
                Console.WriteLine(a);
            }
        }
    }
      

  2.   

    int a=Console.ReadLine();>>>int a = Covert.ToInt32(Console.ReadLine());
      

  3.   

    为什么我这样写不行?
    using System;class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入第一个数");
            int a = int(Console.ReadLine()); //要类型转换
            Console.WriteLine("请输入第二个数");
            int b = int(Console.ReadLine());
            if (a < b)
            {
                Console.WriteLine(b);
            }
            else
            {
                Console.WriteLine(a);
            }
        }
    }
      

  4.   

    Console.ReadLine();  //返回的是string 类型的!
      

  5.   

    哦!我这样转换能不能行呢?
    int a=(int) Console.WriteLine();
      

  6.   

    string转换为int的三种方法 string strValue;
    int intValue;
    第一种:
    intValue=Convert.ToInt32(strValue);第二种:
    intValue=Int32.Parse(strValue);第三种:
    intValue=Int32.TryParse(strValue);三种方法都可以实现string转化为int,但是如果解析失败:
    Int32.Parse()总会抛出异常;
    Convert.ToInt32()在strValue为null的情况下不会抛出异常而是简单的返回0给调用方;
    而Int32.TryParse()则无论如何都不抛出异常,只会返回true或false来说明解析是否成功,如果解析失败,调用方将会得到0值
      

  7.   

    int a=(int) Console.ReadLine();
    /////////////////////////////////
    显式的类型转换时有一些限制,例如值类型,只能在数字、char类型和enum类型之间转换
    不能和引用类型转换!string 为引用类型!
      

  8.   

    int a = (int) Console.WriteLine();
    ==================================
    不行,楼上都解释了很多了
      

  9.   

    感谢JustLovePro(嘉鑫) ,学到了。。