KeyValuePair(Of TKey, TValue)
является структурой (структура), имеет значение по умолчанию, с которым вы можете сравнить.
Dim dictionary As New Dictionary(Of Integer, string)
Dim keyValuePair = dictionary.FirstOrDefault(Function(item) item.Key = 2)
Dim defaultValue AS KeyValuePair(Of Integer, string) = Nothing
If keyValuePair.Equals(defaultValue) Then
' Not found
Else
' Found
End If
Nothing
представляет значение по умолчанию соответствующего типа.
Но потому что вы ищете Dictionary
для ключа, вы можете использовать TryGetValue
вместо
Dim dictionary As New Dictionary(Of Integer, string)
Dim value As String
If dictionary.TryGetValue(2, value) Then
' Found
Else
' Not found
End If