Ejemplo n.º 1
0
        /// <summary>
        /// 对象拷贝
        /// </summary>
        private void objCopy()
        {
            var  models = new List <Temp>();
            Temp tmp    = new Temp()
            {
                item = new TempItem(-1)
            };

            for (int i = 0; i < 5; i++)
            {
                var tmp1 = tmp.DeepClone();// as Temp;
                tmp1.id      = i;
                tmp1.name    = "name" + i;
                tmp1.item.id = i;

                models.Add(tmp1);
            }

            foreach (var item in models)
            {
                Console.WriteLine($"{item.id} {item.name} {item.item.id}");
            }
        }