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

标签 c# visual-studio collections map

在 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/

相关文章:

java - 在 Android 中使用 ORMLite 持久化 ArrayList<String>

c# - 我是在延迟加载这些属性吗?

mysql - 在 Bootstrap 中添加 MySQL

c++ - open62541:引用函数的链接器工具错误

java - 我的 Comparable 实现出了点问题

java - 集合功能方法是否调用 get、put 等?

c# - 在 C# 中对任意大的正整数进行位计数

c# - 什么会导致 WinForms richTextBox.DataBindings.Add() 抛出空引用异常?

c# - 如何编码 .NET 中的结构以供 native 代码使用?

c# - 是否可以访问项目外部的 SetUpFixture?