我正在使用带有.NET 3.5的C#中的字典。我已经创建了一个Dictionary<string, int>对象并传入了StringComparer.Ordinal相等比较器。然而,当我执行以下代码时,我得不到预期的结果:
Dictionary<string, int> theDictionary = new Dictionary<string, int>(StringComparer.Ordinal);
theDictionary.Add("First", 1);
bool exists = theDictionary.ContainsKey("FIRST"); // equals true, when it should not我在这里看不到什么?
发布于 2012-05-26 05:16:48
您确定没有使用StringComparer.OrdinalIgnoreCase吗
使用C# v3.5编译器时,此代码将为我输出false:
using System;
using System.Collections.Generic;
static class Program
{
static void Main()
{
Dictionary<string, int> theDictionary = new Dictionary<string, int>(StringComparer.Ordinal);
theDictionary.Add("First", 1);
bool exists = theDictionary.ContainsKey("FIRST");
Console.WriteLine(exists);
}
}https://stackoverflow.com/questions/10761438
复制相似问题