c# – 如何以这种方式遍历此列表?

c# – 如何以这种方式遍历此列表?,第1张

概述我有一个对象列表,如下所示: ID:2000Title:"Title 1"Description:"My name is Marco"ID:2000Title:"Title 2"Description:"My name is Luca"ID:3000Title:"Title 3"Description:"My name is Paul"ID:4000Title:"Titl 我有一个对象列表,如下所示:
ID:2000Title:"Title 1"Description:"My name is marco"ID:2000Title:"Title 2"Description:"My name is Luca"ID:3000Title:"Title 3"Description:"My name is Paul"ID:4000Title:"Title 4"Description:"My name is Anthony"ID:4000Title:"Title 5"Description:"My name is Carl"ID:4000Title:"Title 6"Description:"My name is Jadett"

现在,我想用每个浏览(遍历)它.但我想从相同的ID开始遍历它.因此,首先是单个/唯一ID(2000,3000,4000,所以3个步骤)的foreach.对于每个“ID”步骤,每个标题/描述:对于ID 2000为2个步骤,对于ID 3000为1,对于ID 4000为3.列表按ID排序.

我该怎么做?通过…分组?呃… …

解决方法 是的,有一个小组:
foreach (var group in items.GroupBy(i => i.ID)){    foreach (var item in group)    {    } }
总结

以上是内存溢出为你收集整理的c# – 如何以这种方式遍历此列表?全部内容,希望文章能够帮你解决c# – 如何以这种方式遍历此列表?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1249865.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存