You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
266 B
12 lines
266 B
3 weeks ago
|
public static class CollectionExtensions
|
||
|
{
|
||
|
public static TValue GetOrAddNew<TKey, TValue>(
|
||
|
this Dictionary<TKey, TValue> dict, TKey key)
|
||
|
where TValue : new()
|
||
|
{
|
||
|
if (!dict.TryGetValue(key, out var value))
|
||
|
dict.Add(key, value = new());
|
||
|
return value;
|
||
|
}
|
||
|
}
|