gpt4 book ai didi

c# - 如何从 IList 中删除重复值,c#

转载 作者:行者123 更新时间:2023-11-30 15:09:38 24 4
gpt4 key购买 nike

我有一个包含 6 条记录的 ilist,类似这样

第一行

时间11:00

地点:

类加罗尔

第二行时间11:00

位置空

....

我必须消除第二行同时 (11:00) 的位置为空

像这样,我将拥有数千条记录,我需要从中删除它。

有什么解决办法吗?

最佳答案

你可以这样做:

list.GroupBy(x=>x.Time)
//from the grouped items select the first one that doesn't have an empty location - you'll have null here if none is found
.Select(x=>x.FirstOrDefault(y=>!string.IsNullOrEmpty(y.Location)))
.ToList()

关于c# - 如何从 IList 中删除重复值,c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4201782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com