比如
      string n = Console.ReadLine();
       if(?)
         {
             //执行数字的程序
         }
        else
          {
            //执行字符串的程序
          }

解决方案 »

  1.   

    string n = Console.ReadLine();
    int num;
    if (int.TryParse(n, out num))
    {
        // num 就是结果数字
        //执行数字的程序
    }
    else
    {
        //执行字符串的程序
    }
      

  2.   

    Char.IsNumber()
    Char.IsLetter() 
      

  3.   

    public static bool IsNumeric(string value)
    {
             return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
    }
    tring n = Console.ReadLine();
    int num;
    if (IsNumeric(n))
    {
        //执行数字的程序
    }
    else
    {
        //执行字符串的程序
    }
      

  4.   

      public static bool RegexValidate(string validateString)
            {
                Regex regex = new Regex("^[0-9]*$");
                return regex.IsMatch(validateString.Trim());           
            }   
           string n = Console.ReadLine();
           bool isNum=RegexValidate(s);
    if(bool ){}else{]
      

  5.   


    bool isNum = false;
    double num = 0;
    try
    {
        num = double.Parse(n);
        isNum = true;
    }
    catch
    {}
    if(isNum)
    {
        // do somthing with num
    }
    else
    {
        // do something with n
    }
      

  6.   

    public static bool IsNumeric(string value)
    {
      return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
    }
    这是什么意思?