Ejemplo n.º 1
0
        /// <summary>
        /// 可以善用   [field: NonSerialized] 設定不可Clone() 的資料
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            Person Temp = new Person()
            {
                Name = "Louis", Password = "******", Sex = "男"
            };
            Person Temp2 = new Person()
            {
                Name = "Candy", Password = "******", Sex = "女"
            };

            PackageData MyDataA = new PackageData();

            MyDataA.info = new Person()
            {
                Name = "Louis", Password = "******", Sex = "男"
            };

            PackageData MyDataB = new PackageData();

            MyDataB.info = new Person()
            {
                Name = "Candy", Password = "******", Sex = "女"
            };

            MyDataA.info.Name += " Lin ";
            var temp = MyDataA.Clone() as PackageData;

            Console.WriteLine($@"Name : {temp.info.Name}  , Password : {temp.info.Password} , Sex : {temp.info.Sex} ");
            //輸出=> Name : Louis Lin   , Password :  , Sex : 男


            MyDataB.info.Name += " Bo ";
            var temp2 = MyDataB.Clone() as PackageData;

            Console.WriteLine($@"Name : {temp2.info.Name}  , Password : {temp2.info.Password} , Sex : {temp2.info.Sex} ");
            //輸出=> Name: Candy Bo, Password :  , Sex: 女
        }