Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
How can I code this correctly to check for null value on the string first?
:sigh:
<pre lang="vb">Dim StrValue As String = value.ToString()
            If StrValue Is Nothing Then
                StrValue = vbNullString
            End If

Posted

1 solution

vbNullString is just null (or Nothing). Check to see if value is null (Nothing) first. If it's null, then do not call ToString on it.

Here's some C# code that does this:

C#
String strValue = value == null ? null : value.ToString();


Here's an automatic conversion to VB syntax (not sure how good it is):

VB
Dim strValue As [String] = If(value Is Nothing, Nothing, value.ToString())
 
Share this answer
 
v3
Comments
technette 10-Feb-11 20:23pm    
Thank you Nishant. It worked.
Nish Nishant 10-Feb-11 20:26pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900