用正则表达式:
string a="0123546abc";
System.Text.RegularExpressions.Regex.IsMatch(a,"^\\d{0,}$")
返回一个布尔值,为真只包含数字

解决方案 »

  1.   

    好办法被人抢先了,写个笨办法;-)
    string s="123a1";
    try
    {
       Convert.ToInt32(s);
       Console.Write("这的确可以转化成数字!");}
    catch
    {
       Console.Write("这样的字符串也想转换成数字呀?");
    }
      

  2.   

    string str = "012354a1250142";
    for(int i = 0;i<str.Length;i++)
    {
        string ss = str.Substring(i,1);
        int ii = string.Compare(ss,"0");
        int jj = string.Compare(ss,"9");
        if(ii < 0 || jj > 0)
        {
    MessageBox.Show("非法字符:" + ss);
        }
    }
    方法较笨,呵呵~~~~
      

  3.   

    The best:
    if not Isnumeric(string) then YES