With VB Option Strict On , why a Nullable(Of T) does not require an explicit cast to the T interface if it requires one to T ?
those.
Dim x As Integer? = 5 Dim y As Integer Dim z As IComparable y = x ' Fails to compile with error ' "Option Strict On disallows implicit conversions from 'Integer?' to 'Integer'." z = x ' Succeeds
EDIT: like the (view) shown by @SSS, part of the answer is that the Nullable values ββare equal, zero and can be Nothing , which is great for a reference such as an interface. Thus, this conversion will always be successful, unlike the conversion to case T (which fails when Nullable does not matter), and therefore it can be considered as an implicit conversion.
Now my question is βhow?β. How is the conversion from Nullable(Of T) (which doesn't have its own interfaces) to the T interface theoretically consistent?
I know that the implementation is box Nullable<T> , which effectively breaks the Nullable wrapper, but I confirm the concept here ...
(So, I will look at the documentation and see if they explain it.)
source share