Created
July 20, 2017 11:50
-
-
Save willmurphyscode/13135fb89fdb6c2e7467e229f4c781c9 to your computer and use it in GitHub Desktop.
A Dictionary<String, T> that ignores the case of its keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace collections | |
{ | |
public class CaseInsensitiveDictionary<T> | |
{ | |
private Dictionary<String, T> _dict; | |
public CaseInsensitiveDictionary() | |
{ | |
_dict = new Dictionary<String, T>(); | |
} | |
public void Set(string key, T value) | |
{ | |
string actualKey = key.ToLower(); | |
_dict[actualKey] = value; | |
} | |
public T Get(string key) | |
{ | |
string actualKey = key.ToLower(); | |
return _dict[actualKey]; | |
} | |
public T this[string key] | |
{ | |
get { return Get(key); } | |
set { Set(key, value); } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment