diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs b/src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs index 58d8f2e4fef46f..0bacc72b32f4d3 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs @@ -1218,10 +1218,16 @@ void ICollection>.CopyTo(KeyValuePair[] } /// - bool ICollection>.Remove(KeyValuePair item) => - TryGetValue(item.Key, out TValue? value) && - EqualityComparer.Default.Equals(value, item.Value) && - Remove(item.Key); + bool ICollection>.Remove(KeyValuePair item) + { + if (TryGetValue(item.Key, out TValue? value, out int index) && EqualityComparer.Default.Equals(value, item.Value)) + { + RemoveAt(index); + return true; + } + + return false; + } /// void IDictionary.Add(object key, object? value) @@ -1237,11 +1243,6 @@ void IDictionary.Add(object key, object? value) throw new ArgumentException(SR.Format(SR.Arg_WrongType, key, typeof(TKey)), nameof(key)); } - if (default(TValue) is not null) - { - ArgumentNullException.ThrowIfNull(value); - } - TValue tvalue = default!; if (value is not null) {