Dato il seguente codice:Tipo nullable con inline se non può funzionare insieme?
Dim widthStr As String = Nothing
Questo funziona - width
viene assegnata Nothing
:
Dim width As Nullable(Of Double)
If widthStr Is Nothing Then
width = Nothing
Else
width = CDbl(widthStr)
End If
ma questo non significa - width
diventa 0.0
(anche se sembra essere il codice logicamente identici):
Dim width As Nullable(Of Double) = If(widthStr Is Nothing, Nothing, CDbl(widthStr))
Perché? C'è qualcosa che posso fare per farlo funzionare?
hai provato lo stesso in C#? 'Raddoppiare? width = widthStr! = null? Double.Parse (widthStr): (double?) Null; ' –
controlla http://stackoverflow.com/questions/14633824/nullable-type-with-inline-if-cannot-work-together http: // stackoverflow. it/questions/2647558 / preserving-null-values-in-a-double-variable – spajce
@HighCore - 'null' in C# e' Nothing' in VB.Net sono * non * equivalenti. 'Nothing' è, approssimativamente,' default (T) '. –