Create a Dictionary<char, char> for matching (in fact, you can create two for reasons of performance and ease of use) or a simple list type with a custom object (for example, List<Tuple<char, char>> ). You can make a way to simplify the addition. Please note that key and val must be unique!
private void Add(char key, char val, Dictionary<char, char> dictionary, Dictionary<char, char> reverseDictionary) { dictionary.Add(key, val); reverseDictionary.Add(val, key); }
Then use this:
Dictionary<char, char> dictionary = new Dictionary<char, char>(); Dictionary<char, char> reverseDictionary = new Dictionary<char, char>(); this.Add('a', '1', dictionary, reverseDictionary); ... char outputChar; if (dictionary.TryGetValue(inputChar, out outputChar)) {
And for the opposite:
char outputChar; if (reverseDictionary.TryGetValue(inputChar, out outputChar)) {
source share