SortedDictionary (C#)-更改值

发布于 2024-07-18 06:29:49 字数 48 浏览 5 评论 0原文

在 SortedDictionary 中,是否可以更改项目的值?

In a SortedDictionary is it possible to change the value of an item ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉生梦死 2024-07-25 06:29:49

是的,为什么不?

sortedDictionary[key] = newValue;

Yes, why not?

sortedDictionary[key] = newValue;
七秒鱼° 2024-07-25 06:29:49

是的,只需像这样使用索引器(在 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();
    }
}

Yes, just use the indexer like this (in 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();
    }
}
烂柯人 2024-07-25 06:29:49

您可以更改值和键,根据定义键是排序的(添加时)

要更改键,请将值存储在临时值中,删除键,然后使用临时值添加新键。

you can change values and keys, by definition keys are sorted (when adding)

To change a key, store value in a temp, remove the key, and Add the new key with the temp value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文