c# - Parallel.ForEach 具有可枚举的 KeyValuePairs?
问题描述
我是否使用了错误的 Parallel ForEach 重载方法?当我使用普通的 ForEach 循环时,我能够获取当前项目,它是预期的正确类型 (KeyValuePair)。
但是当我使用 Parallel 版本时,似乎即使我将鼠标悬停在循环中的当前对象上并且它似乎是正确的类型,我仍然没有得到 Value 和 Key 属性。
提前致谢!
static void TestParallelForEachKeyValuePair(IEnumerable<KeyValuePair<Animal, string>> kvps)
{
foreach (var kvp in kvps)
{
var test = kvp.Key;
}
Parallel.ForEach(kvps, (kvp) =>
{
kvp.
});
}
解决方案
此测试方法有效,但 IntelliSense 未显示“键”和“值”(Windows 窗体)。所以它的智能感知问题。
static void TestParallelForEachKeyValuePair()
{
List<KeyValuePair<int, string>> test = new List<KeyValuePair<int, string>>();
test.Add(new KeyValuePair<int, string>(1, "test1"));
test.Add(new KeyValuePair<int, string>(2, "test2"));
test.Add(new KeyValuePair<int, string>(3, "test3"));
Parallel.ForEach(test, (x) =>
{
MessageBox.Show(x.Key + " " + x.Value);
});
}
推荐阅读
- c++ - IShellFolder::GetDisplayNameOf 返回乱码
- javascript - 来自不同文件中的 const 的 React Native(Redux)调度操作(在父组件中)
- r - 使用 gsub 删除不需要的字符:面临的问题
- sql-server - 错误:nanodbc/nanodbc.cpp:983: 00000: [unixODBC] [驱动程序管理器]无法打开 lib '/usr/local/lib/libmsodbcsql.13.dylib' : 找不到文件
- javascript - 附加时html中的级联下拉列表不起作用
- freepascal - 如何解决此错误:未定义符号
- javascript - Bootstrap 4 工具提示隐藏在按钮单击时不起作用?
- python - pipenv shell 无法创建虚拟环境
- node.js - 服务器错误消息 [ERR_INVALID_ARG_TYPE]:
- php - 在入口点中运行 CMD 输入的命令会导致以代码 0 退出