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 }
结果: