KeyValuePair is nothing

How can we check (.NET 2) if a KeyValuePairhas an assigned value or not?

Dim pair as KeyValuePair(Of A, B) = Nothing

if pair.??? Then Return

Like a structure, it cannot be checked with pair Is Nothing.

Point , for example. has a check . p.IsEmpty

+3
source share
4 answers

Instead of using here the "normal" type - this means that you can not tell the difference between the default value with the values Aand Bas a key and value, you should use Nullable(Of KeyValuePair(Of A, B)).

, , Integer , Nothing 0. 0 "" 0? - Nullable(Of T) . KeyValuePair.

+12

KeyValuePair:

If pair.Equals(New KeyValuePair(Of A, B)) Then Return

. #: fooobar.com/questions/24857/...

+5

Nullable(Of T). .NET 2.0 ( ) , "" , . , " " "", Point, Point at (0, 0) "". a Point, , a Point, . emtpy , ( , ).

, , , Nullable(Of T). ( ) , , . Nullable(Of T) Nothing (null #), .

, ( ) Nullable(Of T) ; Nothing , VB.NET, #. HasValue . , Value , HasValue .

+1

, :

Dim pair as New KeyValuePair(Of A, B)(Nothing, Nothing)
'...'
'<some code that may or may not set pair to KeyValuePair(Of A, B)(Something, Something)>'
'...'
if pair.Key = Nothing Then Return ' some code did not fire

A, B = Nothing Is Nothing.

0

Source: https://habr.com/ru/post/1752862/


All Articles