gpt4 book ai didi

c# - 将带有 List 的字典转换为 IEnumerable

转载 作者:可可西里 更新时间:2023-11-01 09:08:54 24 4
gpt4 key购买 nike

我有一本字典:

Dictionary<String, List<Foo>> test = new Dictionary<String, List<Foo>>();

然后我填充这个字典,因此我需要这个列表以便我可以调用 Add()。我的问题是函数需要返回:

Dictionary<String, IEnumerable<Foo>>

有没有简单的方法可以做到这一点,而无需执行明显的操作并循环遍历我的原始字典并手动执行?

最佳答案

return dictionary.ToDictionary(x => x.Key,x => x.Value.AsEnumerable())

关于c# - 将带有 List 的字典转换为 IEnumerable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28451810/

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