Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created July 20, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmurphyscode/13135fb89fdb6c2e7467e229f4c781c9 to your computer and use it in GitHub Desktop.
Save willmurphyscode/13135fb89fdb6c2e7467e229f4c781c9 to your computer and use it in GitHub Desktop.
A Dictionary<String, T> that ignores the case of its keys
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