gpt4 book ai didi

c# - 使现有的字典不区分大小写 .Net

转载 作者:行者123 更新时间:2023-12-04 00:43:25 30 4
gpt4 key购买 nike

我知道如何使用以下代码使新字典不区分大小写:

var caseInsensitiveDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

但我正在使用 WebApi,它将 JSON 对象序列化为我们创建的类。
public class Notification : Common
{
public Notification();

[JsonProperty("substitutionStrings")]
public Dictionary<string, string> SubstitutionStrings { get; set; }
}

因此,除了在收到“通知”对象后重建字典之外,有没有办法将这个字典设置为首先或在创建之后不区分大小写?

谢谢

最佳答案

So besides rebuilding the dictionary after receiving the "Notification" object, is there a way to set this dictionary to case insensitive in the first place or after it's been created?



不,这是不可能的。您需要创建一个新字典。

目前字典拥有各种不同桶中的所有键;更改比较器将意味着一堆键会突然出现在错误的存储桶中。您需要遍历每个键并重新计算需要移动的位置,这与创建新字典的工作量基本相同。

关于c# - 使现有的字典不区分大小写 .Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25452738/

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