• C# ICloneable接口


     class Program     {         static int Main(string[] args)         {
                //string strDbFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/DataBaseConfiguration.xml");             //string strServerName = GetRegistData("MYSQL_SERVERNAME");             //string strUserName = GetRegistData("MYSQL_LOGINNAME");             //string strPwd = GetRegistData("MYSQL_LOGINPASSWORD");             //XMLProcess.Update(strDbFileName, "/DataBaseConfiguration/SystemDBConfig/Source", strServerName);             //XMLProcess.Update(strDbFileName, "/DataBaseConfiguration/SystemDBConfig/UserID", strUserName);             //XMLProcess.Update(strDbFileName, "/DataBaseConfiguration/SystemDBConfig/PassWord", strPwd);             //XMLProcess.Update(strDbFileName, "/DataBaseConfiguration/BusinessDBConfigCollection/BusinessDBConfig/Source", strServerName);             //XMLProcess.Update(strDbFileName, "/DataBaseConfiguration/BusinessDBConfigCollection/BusinessDBConfig/UserID", strUserName);             //XMLProcess.Update(strDbFileName, "/DataBaseConfiguration/BusinessDBConfigCollection/BusinessDBConfig/PassWord", strPwd);
                MyClass myc1 = new MyClass();             myc1.TestString = "4444444444";             MyClass myc2 = (MyClass) myc1.Clone();
                myc2.TestString = "1111111111";
                Console.WriteLine(  myc1.TestString);
                Console.WriteLine(myc2.TestString);             Console.ReadKey();             return 1;         }

      class MyClass : ICloneable     {         private string _testString;
            public string TestString         {             get { return _testString; }             set { _testString = value; }         }
            #region ICloneable 成员
            public object Clone()         {             MyClass my = new MyClass();             my.TestString =this.TestString;            return my;
                //return this;         }
            #endregion     }

    结果:

     
  • 相关阅读:
    Redis命令
    Linux命令
    SQL语句
    Redis集群
    Redis主主复制、主从复制
    关于Java乱码
    组合, 封装, 访问限制机制, property装饰器, 多态
    继承
    小练习
    面向过程与面向对象, 类和对象
  • 原文地址:https://www.cnblogs.com/studyC/p/2700825.html
Copyright © 2020-2023  润新知