简体   繁体   English

在C#中更改字典值数组中的元素

[英]Changing an element in a dictionary value array in c#

Say I have a Dictionary<int, string[]> dict . 说我有一个Dictionary<int, string[]> dict How could I change a specific element in a string[] in that dictionary, while keeping the others the same? 如何在该词典中更改string []中的特定元素,同时保持其他元素不变? I tried something like this 我尝试过这样的事情

dict[0].ElementAt(0) = "Something Different";

but the left hand side isn't a variable/property/indexer. 但左侧不是变量/属性/索引器。

ElementAt is a method that returns something, it is not the setter. ElementAt是一种返回某些内容的方法,而不是设置方法。 You can use the array-indexer. 您可以使用array-indexer。

dict[0][0] = "Something Different";

ElementAt只是一个访问器,它不支持分配,您应该尝试直接索引访问,例如:

dict[0][0] = "Your String";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM