gpt4 book ai didi

c# - 没有 setter 的属性不能赋值给

转载 作者:行者123 更新时间:2023-12-02 04:41:22 25 4
gpt4 key购买 nike

我正在编写一个包含三列的规范流测试...示例:

|Field  | Key       | Value |
|A | aa | "" |
| | bb | "" |
| | cc | 33 |
| | dd | 1 |
|B | aa | 5 |
| | bb | 4 |
| | cc | 2 |
| | dd | "" |

我添加了这个方法来从表中读取数据:

      var elements = new Dictionary<string, Dictionary<string,string>>().ToList();
var data = table.CreateSet<SpecFlowData>();
elements.AddRange(collection: from item in data
let field =item.Field
let key = item.Key
let value = item.Value
select new Dictionary<string, Dictionary<string,string>>()
{
Keys = field,
Values = new Dictionary<string,string>()
{
Keys= key,
Values = value

}

}

);

我正在尝试为第一列中的每个字段分配一个键值对。但是在构建代码时出现错误“无法将没有 setter 的属性分配给”。任何想法表示赞赏。谢谢。

最佳答案

您不能分配 KeysValuesDictionary<>直接地。但是你可以转换data适当DictionaryDictionaries使用 LINQ:

var result = data.GroupBy(i => i.Field, (k, v) => new
{
Key = k,
Values = v.ToDictionary(x => x.Key, x => x.Value)
})
.ToDictionary(x => x.Key, x => x.Values);

关于c# - 没有 setter 的属性不能赋值给,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764444/

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