Created
February 23, 2018 10:19
-
-
Save hymkor/df48a9a4f94b1bdfe88f2351a06a3000 to your computer and use it in GitHub Desktop.
If Not dic1.TryGetValue(key1,val1) Then val1 = New Foo が多すぎて困る
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Runtime.CompilerServices | |
Module DictExtension | |
<Extension()> | |
Public Function GetOr(Of K, V)(ByVal dict As IDictionary(Of K, V), key As K, ByVal f As Func(Of V)) As V | |
Dim val As V = Nothing | |
If Not dict.TryGetValue(key, val) Then | |
val = f() | |
dict.Add(key, val) | |
End If | |
Return val | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment