Saturday, May 4, 2013

Using Nothing Syntax in VB.NET




When coding in VB.NET you will sometimes want to declare a variable or a string as Nothing. There is a really way to do this and it takes about 1 line of code. Here is how you can do it.


 Sub Main2()
 Dim sString As String = Nothing

 If sString = Nothing Then
     Msgbox("You've got nothing")
 End If

You can also ofcourse combine Nothing with an If-else statement which will help you test to see if the string is actually Nothing.

No comments:

Post a Comment