using System.Collections.Generic; namespace NewHorizons.Utility { public static class CollectionUtilities { public static T KeyByValue(Dictionary dict, W val, T defaultValue = default) { T key = defaultValue; foreach (KeyValuePair pair in dict) { if (EqualityComparer.Default.Equals(pair.Value, val)) { key = pair.Key; break; } } return key; } } }