vb.net 有IsNumeric方法,很方便。
c#可以用这个:
try
   {
      int x = Int32.Parse(textBox1.Text);
      //errorProvider1.SetError(textBox1, "");
   }
   catch (Exception e)
   {
      //errorProvider1.SetError(textBox1, "Not an integer value.");
   }

解决方案 »

  1.   

    可以这样写:string sur = null;
    char temp;
    int L, D, O;    //字母,数字,其它Console.WriteLine("input a string:");
    sur = Console.ReadLine();for (int i = 0, i < sur.Length, i++)
    {
      temp = sur[i];
      if (char.IsLetterOrDigit(temp))    //是字母或数字
      {
        if (char.IsLetter(temp)    //是字母
        {
          L++;    //字母加一
        }
        else
        {
          D++;    //数字加一
        }
      else
      {
        O++;    //其它
      }
    }还有一些别的方法,例如:IsDigit……
      

  2.   

    vb.net 有IsNumeric方法,很方便。
    ---------------------
    同意,C#也可以使用IsNumeric方法,添加引用->Microsoft Visual Basic.Net 
    RunTime ,然后用Microsoft.VisualBasic.Information.IsNumeric()判断是否是数字。如果用捕获异常的方法:
    private bool isDNumeric(string mInput)
    {
    try
    {
       decimal cmicDml=decimal.Parse(mInput);
       return true;
    }
    catch (Exception ex)
       {
            string cmicErr=ex.Message;
            return false;
        }
    }
      

  3.   

    用ASCII码是不是也行呢?虽然老了点
      

  4.   

    try
    {
      int i=int.Parase("123");
    }
    catch
    {
    MessageBox.show("error");
    }
      

  5.   

    一般用int.Parse()就行,不需要太麻烦