Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ContainsKey with TryGetValue #1

Open
OJacot-Descombes opened this issue Apr 25, 2024 · 0 comments · May be fixed by #2
Open

Replace ContainsKey with TryGetValue #1

OJacot-Descombes opened this issue Apr 25, 2024 · 0 comments · May be fixed by #2

Comments

@OJacot-Descombes
Copy link

OJacot-Descombes commented Apr 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant