在 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
中只有一个参数;你必须拉出 Key
和 Value
service.HttpResponseHeaders.Select(kvp => kvp.Key + "->" + kvp.Value)
.Aggregate((s, sx) => s + "," + sx);
关于c# - Visual C# 集合 "map"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806522/