Skip to content

Commit e5eb58c

Browse files
committed
Add GetValueOrDefault extension method for Dictionary
1 parent 9b5ec37 commit e5eb58c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Assets/_PackageRoot/Runtime/Extensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ public static void AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dicti
1919
}
2020
}
2121
}
22+
public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default)
23+
{
24+
return dictionary.TryGetValue(key, out var value) ? value : defaultValue;
25+
}
2226
}
2327
}

0 commit comments

Comments
 (0)