如何对只读 OrderedDictionary 进行深度复制,其中键和值是不再只读的字符串?
orderedDictionary 实例化是这样的:
IOrderedDictionary orderedDictionary= gridview.DataKeys[index].Values;
orderedDictionary 是只读的。
如何制作非只读的orderedDictionary 深层副本?序列化/反序列化不起作用,因为它还会复制只读部分。
The orderedDictionary instantiation is this:
IOrderedDictionary orderedDictionary= gridview.DataKeys[index].Values;
orderedDictionary is read only.
How can I make a deep copy of orderedDictionary that is not read only? Serialization/deserialization doesn't work cause it also copies the read only part.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是复制对象:
更新:
此代码不会创建字典中值的深层副本。
示例:
两个字典都将包含一个带有键“1”的条目和相同的列表。从任何字典中的此列表中删除项目也会更改另一字典中的列表内容,因为只有一个列表。
这将输出以下内容:
将新值分配给一个字典中的键,但对另一个字典没有影响:
这将输出:
The easiest way would be to just copy the objects:
UPDATE:
This code will NOT create a deep copy of the values in the dictionary.
Example:
Both dictionary will contain one entry with the key "1" and the same list. Removing an item from this list in any of the dictionaries will also change the contents of the list in the other dictionary, because there only IS one list.
This will output the following:
Assigning a new value to a key in one of the dictionary however has no effect on the other dictionary:
This will output: