在 SortedDictionary 中是否可以更改项目的值?
hrs
问问题
6091 次
3 回答
12
是的,为什么不?
sortedDictionary[key] = newValue;
于 2009-05-06T20:43:45.573 回答
3
是的,只需像这样使用索引器(在 C# 中):
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
SortedDictionary<int, string> map =
new SortedDictionary<int, string>();
map[1] = "Kevin Hazzard";
Console.WriteLine( map[1] );
map[1] = "W. Kevin Hazzard";
Console.WriteLine( map[1] );
Console.ReadLine();
}
}
于 2009-05-06T20:51:05.930 回答
1
您可以更改值和键,按定义对键进行排序(添加时)
要更改密钥,请将值存储在临时文件中,删除密钥,然后使用临时值添加新密钥。
于 2016-03-04T13:20:11.993 回答