当前位置: 首页 > news >正文

王也高清头像黑帽seo优化

王也高清头像,黑帽seo优化,建筑行业征信查询平台,计算机网站怎么做目录 一、示例代码 二、示例输出 三、注意雷点 四、全字段去重封装方法 1.封装 2.示例 一、示例代码 using System; using System.Collections.Generic; using System.Linq;public class Program {public static void Main(){// 创建一些示例实体对象var people new Li…目录 一、示例代码 二、示例输出 三、注意雷点 四、全字段去重封装方法 1.封装 2.示例 一、示例代码 using System; using System.Collections.Generic; using System.Linq;public class Program {public static void Main(){// 创建一些示例实体对象var people new ListPerson{new Person { Name Alice, Age 30, City New York },new Person { Name Bob, Age 25, City Los Angeles },new Person { Name Alice, Age 30, City New York },//重复的new Person { Name Charlie, Age 35, City Chicago },new Person { Name Alice, Age 28, City San Francisco }};// 1. 单字段去重var uniqueNameFields people.DistinctBy(p p.Name).ToList();Console.WriteLine(指定字段Name去重结果,重复则保留第一条:);foreach (var person in uniqueNameFields){Console.WriteLine($Name: {person.Name}, Age: {person.Age}, City: {person.City});}// 2. 多字段去重var uniqueNameAgeFields people.DistinctBy(p new { p.Name, p.Age }).ToList();Console.WriteLine(\n指定字段Name, Age去重结果,重复则保留第一条:);foreach (var person in uniqueNameAgeFields){Console.WriteLine($Name: {person.Name}, Age: {person.Age}, City: {person.City});}//3.全字段去重// 通过 GroupBy 按 Name 和 Age 字段去重var uniquePeople people.DistinctBy(p new { p.Name, p.Age, p.City }).ToList();Console.WriteLine(\n全字段去重:);foreach (var person in uniquePeople){Console.WriteLine($Name: {person.Name}, Age: {person.Age}, City: {person.City});}} }public class Person {public string Name { get; set; }public int Age { get; set; }public string City { get; set; } }二、示例输出 指定字段Name去重结果,重复则保留第一条: Name: Alice, Age: 30, City: New York Name: Bob, Age: 25, City: Los Angeles Name: Charlie, Age: 35, City: Chicago指定字段Name, Age去重结果,重复则保留第一条: Name: Alice, Age: 30, City: New York Name: Bob, Age: 25, City: Los Angeles Name: Charlie, Age: 35, City: Chicago Name: Alice, Age: 28, City: San Francisco全字段去重: Name: Alice, Age: 30, City: New York Name: Bob, Age: 25, City: Los Angeles Name: Charlie, Age: 35, City: Chicago Name: Alice, Age: 28, City: San Francisco 三、注意雷点 以下代码不能完成全字段去重因为people是引用类型Distinct() 一般用于Liststring,Listint这些值类型去重而不涉及引用类型的字段比较。 people.Distinct().ToList() 若需要全字段去重1.使用DinstinctBy语法加上所有字段。2.使用标题四的封装方法反射实现全字段去重。 四、全字段去重封装方法 1.封装 /// summary /// 通用的全字段去重方法 /// /summary /// returns/returns public static IEnumerableT DistinctByAllFieldsT(IEnumerableT items) {// 获取 T 类型的所有字段值var properties typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);return items.GroupBy(item string.Join(,, properties.Select(p p.GetValue(item)))) // 按所有字段值连接生成唯一标识符.Select(group group.First()); // 取每组的第一个元素 } 2.示例 using System; using System.Collections.Generic; using System.Linq; using System.Reflection;public class Program {public static void Main(){// 创建一些示例实体对象var people new ListPerson{new Person { Name Alice, Age 30, City New York },new Person { Name Bob, Age 25, City Los Angeles },new Person { Name Alice, Age 30, City New York },new Person { Name Charlie, Age 35, City Chicago },new Person { Name Alice, Age 28, City San Francisco }};// 调用封装的去重方法var uniquePeople DistinctByAllFields(people).ToList();Console.WriteLine(根据所有字段去重的结果:);foreach (var person in uniquePeople){Console.WriteLine($Name: {person.Name}, Age: {person.Age}, City: {person.City});}}/// summary/// 通用的全字段去重方法/// /summary/// returns/returnspublic static IEnumerableT DistinctByAllFieldsT(IEnumerableT items){// 获取 T 类型的所有字段值var properties typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);return items.GroupBy(item string.Join(,, properties.Select(p p.GetValue(item)))) // 按所有字段值连接生成唯一标识符.Select(group group.First()); // 取每组的第一个元素} }public class Person {public string Name { get; set; }public int Age { get; set; }public string City { get; set; } }
http://www.w-s-a.com/news/99472/

相关文章:

  • 自己建的网站也要注册域名吗邯郸市做网站
  • 天津网站建设制作软件潍坊个人做网站
  • 重庆城市建设集团官方网站php用什么做网站服务器
  • 深圳坪山站重庆市园林建设有限公司网站
  • 网站建设图片教程如何用自己的电脑建网站
  • 《网页设计与网站建设》A卷答案广东新闻联播
  • 海南专业网站运营托管wordpress 去掉主题
  • 企业品牌网站制作甜品制作网站
  • 手机网站怎么制作影响力网站建设
  • 猪八戒网站做私活赚钱吗一尊网 又一个wordpress站点
  • 上海市做网站的公司滨州哪里做网站
  • 简单的网站建设步骤wordpress 贴吧主题
  • 金泉网做网站找谁表格做网站
  • 北京做兼职从哪个网站好江西省建设监督网站电子网
  • 什么网站做生鲜比较好安徽建设厅城乡官网
  • 域名购买网站有哪些问题上海装修网站建设
  • 找人做seo要给网站程序河北建设网网站
  • 哪家做网站性价比高wordpress最新文章链接插件
  • 维修网站怎么做移动互联网应用程序指的是什么
  • 张家界建设网站门户网站的建设原理
  • 企业通用网站模板湖南网站建设企业
  • 能看网站的视频app如何运行asp网站
  • 公司做网站还是做阿里好呢国外的旅游网站做的如何
  • 怎么做wep网站长沙seo排名公司
  • 海南网站网络推广做转运网站
  • 门户网站方案用户等待网站速度
  • 哈尔滨专业建网站方案深圳生活免费信息网
  • 检测网站是否被挂黑链wordpress 网址分享
  • 网站建设贵阳东莞网站建设策划
  • 网站5建设需要学什么桃城网站建设公司