namespace System.Collections.Generic; /// /// A helper type with extensions for the type. /// internal static class DictionaryExtensions { /// /// Tries to remove an item from a instance and returns it if present. /// /// The type of dictionary keys. /// The type of dictionary values. /// The input instance. /// The lookup key to use. /// The resulting item, if present. /// Whether or not an item was found with the given key. public static bool Remove(this Dictionary dictionary, TKey key, out TValue? value) where TKey : notnull { if (dictionary.TryGetValue(key, out value)) { _ = dictionary.Remove(key); return true; } return false; } }