using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//我以前都這麼處理不分大小寫的Hashtable
Dictionary<string, int> sillyBoy =
new Dictionary<string, int>();
//新增時將所有Key強迫轉小寫
sillyBoy.Add("Darkthread".ToLower(), 9999);
//比較時也強迫轉小寫就好了呀
if (sillyBoy.ContainsKey("DARKTHREAD".ToLower()))
Console.WriteLine("阿母啊! 哇行公啊~~");
//當時覺得我好會想辦法解問題,沒想到自己根本是
//笨小孩笨小孩笨小孩笨小孩笨小孩笨小孩笨小孩笨小孩
//原來,Dictionary<T, T>的建構式可傳入Comparer當參數
Dictionary<string, int> dict =
new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
dict.Add("Darkthread", 32767);
Console.WriteLine(dict["DARKTHREAD"]);
Console.WriteLine(dict["darkthread"]);
//是的,醬子就可以搞定。我以後不會再阿呆了
Console.Read();
}
}
}