[c++]
char *i1=new char[3];
char *i2=new char[3];
cahr *temp;
temp=i1;
i1=i2;
i2=temp;
temp=NULL;
以上如何翻译到C#,有同样效果就行,不一定要不申请新空间,但内部数据逐一复制就不用了.

解决方案 »

  1.   

    static void Main(string[] args)
    {
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    char [] i1=new char [3]{'a','b','c'};
    char [] i2=new char [3]{'e','f','g'};
    char [] temp=null;
    temp=i1;
    i1=i2;
    i2=temp;
    Console.WriteLine (i1);
    Console.WriteLine (i2);
    //c#中temp不用写temp=null,交给GC处理
    }
      

  2.   

    谢谢,不过我出的问题涉及到访问器;如果char[]包含在一个类中,在内里定义一个访问器
    public char Chars{
    get{...}set{...}
    }
    上述操作全部用访问器实现(temp不一定要用类,i1,i2是类实例),问下怎么做,我老是访问失败.
      

  3.   

    错了应该改成
    public char []Chars{
    get{...}set{...}
    }
      

  4.   

    string s1;
    string s2;
    string temp;
    temp=i1;
    i1=i2;
    i2=temp;