gpt4 book ai didi

linq - 将 dataReader 转换为 Dictionary

转载 作者:行者123 更新时间:2023-12-04 16:40:27 25 4
gpt4 key购买 nike

我尝试使用 LINQ 将一行转换为 Dictionary (fieldName -> fieldValue)

return Enumerable.Range(0, reader.FieldCount)
.ToDictionary<string, object>(reader.GetName, reader.GetValue);

但我收到错误消息:

实例参数:无法从 'System.Collections.Generic.IEnumerable<int>' 转换至 'System.Collections.Generic.IEnumerable<string>'
如何纠正这个?

最佳答案

return Enumerable.Range(0, reader.FieldCount)
.ToDictionary(
i => reader.GetName(i),
i => reader.GetValue(i));

关于linq - 将 dataReader 转换为 Dictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11842651/

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