System.Convert.ToInt32()
System.Convert.ToInt16()

解决方案 »

  1.   

    楼上的兄弟说了,不过还有一个方法你试试,String s = "the string you want to convert";
    String convertS;convertS = CType( s, Int32);
      

  2.   

    try
    {
        Int32.Parse(yourstring);
    }
    catch(Exception ee)
    {
        messagebox.show("不能转换")
    }
      

  3.   

    if(TypeDescriptor.GetConverter(typeof(int)).CanConvertFrom(typeof(string)))
    {
       try
       {
          int i=(int)TypeDescriptor.GetConverter(typeof(int)).ConvertFrom("0");
       }
       catch 
       {
       }
    }
      

  4.   

    string mystr="5";
    int myint=int.Parse(mystr);
      

  5.   

    TO rplus() : 
    CType 是 VB.NET 函数吧?C# 用不了吧?
      

  6.   

    string m ="9999" 
    int i = System.Conver.Toint32(m);
      

  7.   

    if(TypeDescriptor.GetConverter(typeof(int)).CanConvertFrom(typeof(string)))
    {
       try
       {
          int i=(int)TypeDescriptor.GetConverter(typeof(int)).ConvertFrom("0");
       }
       catch 
       {
       }
    }
    qqq123(qqq123)  写的酷
      

  8.   

    字符串轉為 INT 時,要捕捉異常。
    方法我就不用說了,樓主該有了。