dotnet / dotnet/dotnet-api-docs

List<T>.Remove() and SortedSet<T>.Remove() should accept null only for nullable reference types

Open
#5,205 1 comment 0 reactions 0 assignees View on GitHub
area-System.Collections Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

`List.Remove()` and `SortedSet.Remove()` say in their API documentation that the passed item can be `null` for reference types:

* https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.remove?view=net-5.0
* https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.sortedset-1.remove?view=net-5.0

However, calling those methods with a nullable variable will cause warning CS8604 "Possible null reference argument for parameter 'item' in 'bool SortedSet.Remove(Scenario item)'", if `T` itself isn't a nullable reference type.

I filed issue dotnet/runtime#46620 about it, assuming the method annotation to be wrong. But it isn't. The problem is just the documentation which is a bit misleading due to predating non-nullable reference types.

I propose updating the docs of those two methods to say that the passed item can be `null` for *nullable* reference types.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.