-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
Description
Description
SortedList<TKey, TValue> with struct TKey allocates memory due to boxing of TKey.
Configuration
Net 8,0
Analysis
Several methods in SortedList (e.g., Add, Remove, IndexOf) verify that the key is not null by invoking ArgumentNullException.ThrowIfNull(key);. ThrowIfNull expects an object parameter, causing TKey to be boxed when it is a struct type. This behavior should be avoided for struct types. It might be beneficial to add a generic overload to ArgumentNullException that does not allocate memory for struct types. This change could be useful as similar scenarios might occur in other generic classes within .NET.