Skip to content

Prefer Dictionary<K, V>.TryAddValue(key) over guarded Add(key) #33799

@terrajobst

Description

@terrajobst

!Dictionary<K, V>.ContainsKey(key) followed by Dictionary<K, V>.Add(key) can be combined into a single TryAdd call.

Category: Performance

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Collectionscode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions