.NET – Compare integers and integers? The result is a Boolean value? Not a Boolean

I just write some code to compare the id of an integer with the id of an integer? For example:

Dim id As Integer = 1
Dim nullId As Integer? = Nothing
Dim areEqual As Boolean
areEqual = nullId = id

When I try to compile the code, I get a compiler error:

Option Strict On disallows implicit conversions from'Boolean?' to 'Boolean'.

Although I can easily solve this problem, I hope someone can explain what is happening in the compiler to issue this warning.

This is one of the quirks of nullable types. NULL (generally speaking) means “don’t know”. Compare known and unknown unknown results (because you don’t Know if they are the same).

It is the same as the nullable type in .NET. Compare an integer? Will using Integer result in boolean values? , Because you may get True, False or “don’t know”.

I just write some code to compare the id of an integer with the id of an integer? For example:

Dim id As Integer = 1
Dim nullId As Integer? = Nothing
Dim areEqual As Boolean
areEqual = nullId = id

When I try to compile the code, I get a compiler error:

Option Strict On disallows implicit conversions from'Boolean?' to 'Boolean'.

Although I can easily solve this problem, I hope someone can explain what is happening in the compiler to issue this warning.

This is one of the quirks of nullable types. NULL (generally speaking) means “don’t know”. Compare known and unknown unknown results (because you don’t know if they are the same).

It is the same as the nullable type in .NET. Compare an integer? Will using Integer result in boolean values? , Because you may get True, False or “don’t know”.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3367 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.