Skip to content

Replace ContainsKey with TryGetValue #1

Description

@OJacot-Descombes

A call to ContainsKey(key) followed by an access var set = this[key] results in a double lookup in the dictionary.

Resolution: Replace ContainsKey with TryGetValue.

The code can also be simplified by using collection initializers.

See also: CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions