wordpress站群代oa系统网站建设

news/2025/9/23 9:27:45/文章来源:
wordpress站群代,oa系统网站建设,如何做网站推广自己产品,天津城市建设大学网站概述#xff1a;以上内容详细介绍了在 C# 中实现不改变原 List 值的多层嵌套复制方法#xff0c;包括使用 AutoMapper、Json.NET、以及对象序列化的步骤和示例。这些方法提供了灵活而高效的方式#xff0c;可以根据项目需求选择最适合的深度复制方式。 1. 使用 AutoMapper …概述以上内容详细介绍了在 C# 中实现不改变原 List 值的多层嵌套复制方法包括使用 AutoMapper、Json.NET、以及对象序列化的步骤和示例。这些方法提供了灵活而高效的方式可以根据项目需求选择最适合的深度复制方式。 1. 使用 AutoMapper 进行多层嵌套复制 AutoMapper 是一个对象映射工具可以方便地进行对象之间的映射。以下是使用 AutoMapper 实现多层嵌套复制的步骤和示例 首先你需要在项目中安装 AutoMapper 包。你可以通过 NuGet 包管理器控制台运行以下命令来安装 Install-Package AutoMapper 然后你可以使用以下代码进行深度复制 using AutoMapper; using System; using System.Collections.Generic;class Person {public string Name { get; set; }public int Age { get; set; } }class Student {public string StudentId { get; set; }public Person Info { get; set; } }class Program {static void Main(){// 创建原始 List多层嵌套ListStudent originalList new ListStudent{new Student { StudentId 001, Info new Person { Name Alice, Age 25 } },new Student { StudentId 002, Info new Person { Name Bob, Age 30 } }};// 使用 AutoMapper 实现深度复制ListStudent copiedList DeepCopyWithAutoMapper(originalList);// 修改复制后的值copiedList[0].Info.Name Charlie;// 打印原始值验证原始 List 的值是否改变Console.WriteLine(原始 List 的值);PrintList(originalList);// 打印复制后的值Console.WriteLine(\n复制后 List 的值);PrintList(copiedList);}static ListStudent DeepCopyWithAutoMapper(ListStudent originalList){// 初始化 AutoMapper 配置var config new MapperConfiguration(cfg {// 针对每一层嵌套的类型进行映射配置cfg.CreateMapStudent, Student();cfg.CreateMapPerson, Person();});// 创建映射器IMapper mapper config.CreateMapper();// 使用映射器进行深度复制ListStudent newList mapper.MapListStudent(originalList);return newList;}// 打印 List 的方法static void PrintList(ListStudent list){foreach (var student in list){Console.WriteLine($StudentId: {student.StudentId}, Name: {student.Info.Name}, Age: {student.Info.Age});}} } 在这个示例中首先初始化 AutoMapper 配置然后创建映射器并使用映射器进行深度复制。 2. 使用 Json.NET 进行多层嵌套复制 Json.NETNewtonsoft.Json是一个用于处理 JSON 数据的强大库也可以用于实现深度复制。以下是使用 Json.NET 实现多层嵌套复制的步骤和示例 首先你需要在项目中安装 Json.NET 包。你可以通过 NuGet 包管理器控制台运行以下命令来安装 Install-Package Newtonsoft.Json 然后你可以使用以下代码进行深度复制 using Newtonsoft.Json; using System; using System.Collections.Generic;class Person {public string Name { get; set; }public int Age { get; set; } }class Student {public string StudentId { get; set; }public Person Info { get; set; } }class Program {static void Main(){// 创建原始 List多层嵌套ListStudent originalList new ListStudent{new Student { StudentId 001, Info new Person { Name Alice, Age 25 } },new Student { StudentId 002, Info new Person { Name Bob, Age 30 } }};// 使用 Json.NET 实现深度复制ListStudent copiedList DeepCopyWithJson(originalList);// 修改复制后的值copiedList[0].Info.Name Charlie;// 打印原始值验证原始 List 的值是否改变Console.WriteLine(原始 List 的值);PrintList(originalList);// 打印复制后的值Console.WriteLine(\n复制后 List 的值);PrintList(copiedList);}static ListStudent DeepCopyWithJson(ListStudent originalList){// 使用 JsonConvert 进行深度复制string json JsonConvert.SerializeObject(originalList);ListStudent newList JsonConvert.DeserializeObjectListStudent(json);return newList;}// 打印 List 的方法static void PrintList(ListStudent list){foreach(var student in list){Console.WriteLine($StudentId: {student.StudentId}, Name: {student.Info.Name}, Age: {student.Info.Age});}} } 在这个示例中使用 JsonConvert 将原始 List 转换为 JSON 字符串然后再从 JSON 字符串中反序列化得到新的 List实现了深度复制。 3. 使用对象序列化和反序列化进行深度复制 另一种常见的方法是使用 C# 的对象序列化和反序列化功能将对象序列化为字节流然后再反序列化为新的对象。以下是使用序列化和反序列化实现多层嵌套复制的步骤和示例 using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary;class Person {public string Name { get; set; }public int Age { get; set; } }class Student {public string StudentId { get; set; }public Person Info { get; set; } }class Program {static void Main(){// 创建原始 List多层嵌套ListStudent originalList new ListStudent{new Student { StudentId 001, Info new Person { Name Alice, Age 25 } },new Student { StudentId 002, Info new Person { Name Bob, Age 30 } }};// 使用序列化和反序列化实现深度复制ListStudent copiedList DeepCopyWithSerialization(originalList);// 修改复制后的值copiedList[0].Info.Name Charlie;// 打印原始值验证原始 List 的值是否改变Console.WriteLine(原始 List 的值);PrintList(originalList);// 打印复制后的值Console.WriteLine(\n复制后 List 的值);PrintList(copiedList);}static ListStudent DeepCopyWithSerialization(ListStudent originalList){IFormatter formatter new BinaryFormatter();using (MemoryStream stream new MemoryStream()){formatter.Serialize(stream, originalList);stream.Seek(0, SeekOrigin.Begin);return (ListStudent)formatter.Deserialize(stream);}}// 打印 List 的方法static void PrintList(ListStudent list){foreach (var student in list){Console.WriteLine($StudentId: {student.StudentId}, Name: {student.Info.Name}, Age: {student.Info.Age});}} } 在这个示例中使用 BinaryFormatter 将原始 List 序列化为字节流然后再反序列化得到新的 List实现了深度复制。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/912051.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

直播营销的优势有哪些北京路口优化

先说POSIX的吧: mq_open,sem_open,shm_open着三个函数用于创建或者打开一个IPC通道。 由此可见,消息队列的读写权限是任意的,然而信号灯就没有,…

C#和Lua相互访问 - 详解

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

国外那些网站是做菠菜的平面设计要什么学历

​​​​​​​ 概要 随着前端技术的快速发展,前后端分离已经成为了一种趋势。在前后端分离的架构中,前端需要与后端进行数据的交互,这就需要后端提供RESTful API接口。而在开发过程中,我们常常需要模拟后端数据接口&#xf…

jemter 安装

附上链接:https://blog.csdn.net/m0_65120252/article/details/136568884无可奈何花落去,似曾相识燕归来

Day20创建对象内存分析

package oop1.Demo3;public class pet {public String name;public int age;//无参构造public void shout(){System.out.println("叫了一声");} }package oop1;import oop1.Demo3.pet;public class Applicat…

熬夜三天!SpringCloud Gateway 动态路由失效,背后黑手竟是它……

在微服务体系里,SpringCloud Gateway 作为流量调度的核心组件,其路由配置的稳定性,直接关系到整个系统能否正常运转。之前,我们团队负责的项目借助 Apollo 配置中心,构建起一套动态路由机制。代码源自官方范例(ap…

flash网站收录怎样建设邮箱网站

欢迎来到白刘的领域 Miracle_86.-CSDN博客 系列专栏 C语言知识 先赞后看,已成习惯 创作不易,多多支持! 目录 一、 字符指针变量 二、数组指针变量 2.1 数组指针变量是什么 2.2 数组指针变量如何初始化 三、二维数组传参本质 四、函数…

无锡网站建设要多少钱vs音乐网站开发实例

文章目录 前言运营指标指标范围参考值留存指标的意义总结 前言 作为游戏人免不了听到 DAU 、UP值、留存 等名词,并且有些名词听起来还很像,特别是一款上线的游戏,这些游戏运营指标是衡量游戏业务绩效和用户参与度的重要数据,想做…

金川做网站公司互通登录插件WordPress

2023-12-16每日一题 一、题目编号 2276. 统计区间中的整数数目二、题目链接 点击跳转到题目位置 三、题目描述 给你区间的 空 集,请你设计并实现满足要求的数据结构: **新增:**添加一个区间到这个区间集合中。 **统计:**计算…

各种网站的区别WordPress中文king主题

(1)当访问共同的代码的时候:可以使用同一个Runnable对象,这个Runnable对象中有这个共享数据,比如卖票系统就可以这么做。或者这个共享数据封装在一个对象当中,然后对这个对象加锁,也可以实现数据安全访问。public clas…

网站源码换模板建设银行网站的特点分析

for 循环 For … in 语句是另一种循环语句,其特点是会在一系列对象上进行迭代(Iterates),即它会遍历序列中的每一个项目 注意: 1、else 部分是可选的。当循环中包含它时,它循环中包含它时,它总会…

12数据网站建设制作网页网站的软件

文章目录 📖 前言1. 通信背景1.1 进程通信的目的:1.2 管道的引入: 2. 匿名管道2.1 匿名管道的原理:2.2 匿名管道的创建:2.3 父子进程通信:2.3.1 read()阻塞等待 2.4 父进程给子进程派发任务:2.5…

自己做的小说网站要交税吗网站建设企业建站哪家好?来这里看看

在Apache Flink这一现代大数据处理框架中,对实时流数据的高效、准确处理是一个核心诉求。为实现这一目标,Flink引入了一种独特而强大的时间管理机制——水印(Watermark),它在处理无界流时起到了关键的作用,…

解析 Authenticode 部分代码。

#include "base/strings/utf_string_conversions.h" #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endi…

cmd 执行git bash 命令

"D:\Program Files\Git\bin\bash.exe" -c "ls"

实用指南:力扣2132. 用邮票贴满网格图

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

安全向量模板类SiVector - 实践

安全向量模板类SiVector - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco&quo…

ONCHAINID源码分析(二)

ONCHAINID源码分析(二)上一章节我们对ONCHAINID做了一个总览、对各个组成部分做了概要性质的讲解,然后着重对整套合约的部署框架和代理合约设计做了代码分析。这使得我们对整体有了一定的理解,本章我们继续学习ONCHA…

gl账号注册网站沧州网站优化价格

🌟 前言 欢迎来到我的技术小宇宙!🌌 这里不仅是我记录技术点滴的后花园,也是我分享学习心得和项目经验的乐园。📚 无论你是技术小白还是资深大牛,这里总有一些内容能触动你的好奇心。🔍 &#x…

福田网站建设流程网站设计网页配色

std::future —C17 多线程 std::future C标准程序库使用future来模拟这类一次性事件:若线程需等待某个特定的一次性事件发生,则会以恰当的方式取得一个future,它代表目标事件;接着,该线程就能一边执行其他任务&#…