C# List 拷贝

                Gateway_Info.List_AllDeviceInfos.Add(
                    new Property_DeviceInfo
                    {
                        DeviceIndex = Index,
                        DeviceName = Name,
                        List_YX = new List<Property_XmlPara>(),
                        List_YC = new List<Property_XmlPara>(),
                        List_YK = new List<Property_XmlPara>()
                    }) ;
                //
                // List 引用复制  指向为同一地址
                //List_YxPara.ForEach(i => Gateway_Info.List_AllDeviceInfos[Gateway_Info.List_AllDeviceInfos.Count - 1].List_YX.Add(i));
                //List_YcPara.ForEach(i => Gateway_Info.List_AllDeviceInfos[Gateway_Info.List_AllDeviceInfos.Count - 1].List_YC.Add(i));
                //List_YkPara.ForEach(i => Gateway_Info.List_AllDeviceInfos[Gateway_Info.List_AllDeviceInfos.Count - 1].List_YK.Add(i));
                //
                // List 深度拷贝  指向为不同地址
                Gateway_Info.List_AllDeviceInfos[Gateway_Info.List_AllDeviceInfos.Count - 1].List_YX = FuncHelper.List_Helper.Clone(List_YxPara);
                Gateway_Info.List_AllDeviceInfos[Gateway_Info.List_AllDeviceInfos.Count - 1].List_YC = FuncHelper.List_Helper.Clone(List_YcPara);
                Gateway_Info.List_AllDeviceInfos[Gateway_Info.List_AllDeviceInfos.Count - 1].List_YK = FuncHelper.List_Helper.Clone(List_YkPara);

 

posted @ 2022-08-26 10:06  sanmannn  阅读(820)  评论(0)    收藏  举报