Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Use of question mark in parameters
Message
From
07/11/2011 11:42:48
 
 
To
07/11/2011 11:38:25
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01528240
Message ID:
01528264
Views:
41
>>It isn't really nulls - it's a nullable structure
>
>Ok, thanks, BTW, I have this:
>
>
>        ' Avoid to receive a null
>        ' expD1 Value
>        Public Function GetNonNullable(ByVal tdValue As Date?) As Date
>            Dim ldValue As Date = Nothing
>
>            ' If we have a value
>            If tdValue.HasValue Then
>                ldValue = tdValue
>            Else
>                ldValue = oApp.GetEmptyDate()
>            End If
>
>            Return ldValue
>        End Function
>
>        ' Avoid to receive a null
>        ' expN1 Value
>        Public Function GetNonNullable(ByVal tnValue As Double?) As Double
>            Dim lnValue As Double = 0
>
>            ' If we have a value
>            If tnValue.HasValue Then
>                lnValue = tnValue
>            End If
>
>            Return lnValue
>        End Function
>
>        ' Avoid to receive a null
>        ' expL1 Value
>        Public Function GetNonNullable(ByVal tlValue As Boolean?) As Boolean
>            Dim llValue As Double = False
>
>            ' If we have a value
>            If tlValue.HasValue Then
>                llValue = tlValue
>            End If
>
>            Return llValue
>        End Function
>
>        ' Avoid to receive a null
>        ' expN1 Value
>        Public Function GetNonNullable(ByVal tnValue As Integer?) As Integer
>            Dim lnValue As Integer = 0
>
>            ' If we have a value
>            If tnValue.HasValue Then
>                lnValue = tnValue
>            End If
>
>            Return lnValue
>        End Function
>
>        ' Avoid to receive a null
>        ' expC1 Value
>        Public Function GetNonNullable(ByVal tcValue As String?) As String
>            Dim lcValue As Integer = ""
>
>            ' If we have a value
>            If tcValue.HasValue Then
>                lcValue = tcValue
>            End If
>
>            Return lcValue
>        End Function
>
>
>However, for the String type, the designer gives an error. It says "Type 'String' must be a value type or a type argument constrained to 'Structure' in order to be used with 'Nullable' or nullable modifier '?'". I will try with the other approach to see if that would work.


nullable only applies to value types. Since string is a reference type, it can be null

You may want to take the ? out of String?, test for null like for any other reference type, and if it is null, return the empty string for example
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform