private bool judge(string s)
{
try{ Convert.toInt32(s);return true;}
catch{return false;}
}

解决方案 »

  1.   

    对于简单的,可以用抓异常的方式来实现:
    比如:
    try
    {
    int.Parse("ab");
    }
    catch(FormatException ex)
    {
    MessageBox.Show("Is not a number");

    }也可以使用正则:
    string s ="12";
    if(!System.Text.RegularExpressions.Regex.IsMatch(s,@"^\d*$"))
    {
    //Is number
    }
      

  2.   

    or char.isnumbera sample:using System;public class IsNumberSample {
       public static void Main() {
          string str = "non-numeric";      Console.WriteLine(Char.IsNumber('8'));      // Output: "True"
          Console.WriteLine(Char.IsNumber(str, 3));   // Output: "False"
       }
    }