b) -> [a] -> [b] 使用函数更改集合的类型。 C#中有类似的东西吗? 或者将完整的 KeyValuePairs 集合放入调试消息中的-6ren">
gpt4 book ai didi

c# - Visual C# 集合 "map"函数?

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

在 Haskell 中我们有函数

map (a -> b) -> [a] -> [b]

使用函数更改集合的类型。

C#中有类似的东西吗?

或者将完整的 KeyValuePairs 集合放入调试消息中的最快方法是什么?

我想到了某事

debugmsg("http response is " + service.HttpResponseHeaders
.Map<string>((k, v) => k + "->" + v)
.Aggregate((s, sx) => s + "," + sx)
+ ". ");

最佳答案

在 LINQ 中,map被命名为Select .另外,请注意 KeyValuePair<TKey, TValue> 的任何集合在 Select 中只有一个参数;你必须拉出 KeyValue

service.HttpResponseHeaders.Select(kvp => kvp.Key + "->" + kvp.Value)
.Aggregate((s, sx) => s + "," + sx);

关于c# - Visual C# 集合 "map"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806522/

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