Last active
February 22, 2017 08:06
-
-
Save treefortress/de581564b86401d7e935 to your computer and use it in GitHub Desktop.
StringHash Class for C# - For easy creation of string-based Hashtables
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 UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class StringHash<T> { | |
Dictionary<string, T> dictionary = new Dictionary<string, T>(); | |
public void Set(string key, T value) { | |
if (HasKey(key)) { | |
dictionary.Remove(key); | |
} | |
dictionary.Add(key, value); | |
} | |
public bool HasKey(string key) { | |
return dictionary.ContainsKey(key); | |
} | |
public T Get(string key) { | |
if (dictionary.ContainsKey(key)) { | |
T val; | |
dictionary.TryGetValue(key, out val); | |
return val; | |
} | |
return default(T); | |
} | |
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