我想让所有的string都能有一个ToInt的功能,应该加到哪里呢?

解决方案 »

  1.   

    1。 直接用Convert.toint32 () 
    2。继承string类,然后再加你自己函数
      

  2.   

    to:   2。继承string类,然后再加你自己函数用上面的方法之后,可以这样用吗:
    int i = TextBox1.Text.ToInt();   //这是我想要的效果
      

  3.   

    [C#]
    [Serializable]
    public sealed class String : IComparable, ICloneable,
       IConvertible, IEnumerable
      

  4.   

    sealed密封类不能被继承。将密封类用作基类是错误的。在类声明中使用 sealed 修饰符可防止继承此类。
      

  5.   

    可以做一个包含静态ToInt方法的类MyString
    int i = MyString.ToInt(TextBox1.Text);
      

  6.   

    不可以继承没关系,你可以写一个类.把这个类包含进去
    public class MyString 
        {
           String str = new String();
           
        }