Skip to content

Prefer Dictionary<K, V>.TryGetValue() over guarded indexer access #33798

@terrajobst

Description

@terrajobst

Dictionary<K, V>.ContainsKey(key) followed by Dictionary<K, V>.this[key] can be combined into a single TryGetValue 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