18 lines
398 B
Plaintext
18 lines
398 B
Plaintext
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
int UpdateValue(ConcurrentDictionary<int, int> dict, int key) =>
|
|
dict.GetOrAdd(key, _ => key + 42);
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
int UpdateValue(ConcurrentDictionary<int, int> dict, int key) =>
|
|
dict.GetOrAdd(key, x => x + 42);
|
|
----
|