gpt4 book ai didi

c# - 查找字典的不同值

转载 作者:太空狗 更新时间:2023-10-29 22:26:18 27 4
gpt4 key购买 nike

我有一个 GroupSummary class它有一些像这样的属性:

public class GroupsSummary
{
public bool FooMethod()
{
////
}
public bool UsedRow { get; set; }

public string GroupTin { get; set; }
public string PayToZip_4 { get; set; }
public string PayToName { get; set; }

public string PayToStr1 { get; set; }
public string PayToStr2 { get; set; }
public string PayToCity { get; set; }
public string PayToState { get; set; }
public bool UrgentCare_YN { get; set; }
}

然后我有一个Dictionary喜欢<string, List<GroupsSummary>

对于这些字典项中的每一个,我都想找到所有distinct 地址,但是为我定义不同地址的此类的属性是

PayToStr1,PayToStr2,PayToCity,PayToState

据我所知,我可以说类似 mydictionartItem.select(t => t).Distinct().ToList() 的内容但我认为将比较此类的所有属性是错误的。那么我该如何解决呢?

最佳答案

var newDict = dict.ToDictionary(
x=>x.Key,
v=>v.Value.GroupBy(x=>new{x.PayToStr1, x.PayToStr2, x.PayToCity, x.PayToState})
.Select(x=>x.First())
.ToList());

关于c# - 查找字典的不同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25087266/

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