C#的System.String等都可以不必实例化而使用(可能实例化了,但是不用new)。而它的Trim()是属性?方法?
怎么就能模仿出自己的类型
Class My
{
     .........
    public string Base64()
    {
        ...............
        return this.ToString();
    }
}
My my = (My)"asdasdasd";   ?看上去这样实现有点问题。怎么就能出它的直接类型了?而不用转换什么的。my.Base64();   //能达到加密为Base64加密,这是自己写的个方法
就象JavaScript的
String.prototype.Trim = function() 

return this.replace(/(^\s*)|(\s*$)/g, ""); 

用法一样

解决方案 »

  1.   

    String 类 定义 时候
    重载了= 而已
    实际上是实力化了的
      

  2.   

    Trim()后面带了括号,肯定是方法。
      

  3.   

    自己实例化也没什么关系,主要是类型问题,如何给它分配类型啊。能让某个东西能等于他
    比如
    string a = "23";      //象这样能赋值
    int b = int.Parse(a); //这样最起码能转换虽然用另外的比如
    My my = new My("23");
    my.Base64();
    也能实现,不过不能实现和C#一样的效果么?
      

  4.   

    增加隐式转换符即可,参看
    class MyType 
    {
       public static implicit operator int(MyType m) 
       {
          // code to convert from MyType to int
       }
    }
      

  5.   

    class MyType 
    {
    public static implicit operator int(MyType m) 
    {
    // code to convert from MyType to int
    return 1;
    } public static implicit operator MyType( string m) 
    {
    // code to convert from MyType to int
    return new MyType();
    }
    }
    //call
    MyType myType = "aaa";