I am trying to assign empty char using
Private m_ClientAreaCode As Char = ''
But I am not able to assign.
I am trying to assign empty char using
Private m_ClientAreaCode As Char = ''
But I am not able to assign.
Here is a little app that shows the many possibilities. What is interesting to note is the output when using this character.
Private m_ClientAreaCode As Char
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Debug.WriteLine("")
Dim test1 As String = "one"
Dim test2 As String = "two"
Dim test As String
test = " 1 " & test1 & m_ClientAreaCode & test2
Debug.WriteLine(test)
m_ClientAreaCode = Nothing
test = " 2 " & test1 & m_ClientAreaCode & test2
Debug.WriteLine(test)
m_ClientAreaCode = Chr(0)
test = " 3 " & test1 & m_ClientAreaCode & test2
Debug.WriteLine(test)
m_ClientAreaCode = ControlChars.NullChar
test = " 4 " & test1 & m_ClientAreaCode & test2
Debug.WriteLine(test)
m_ClientAreaCode = CChar("")
test = " 5 " & test1 & m_ClientAreaCode & test2
Debug.WriteLine(test)
End Sub
Output
1 one 2 one 3 one 4 one 5 one
The output is missing 'two' and appears on the same line. The string contains the characters but certain methods deal with the 'null' differently. Just be aware.
You will want to read this,
Just use Nothing for this
Private m_ClientAreaCode As Char = Nothing
In VB.Net
Nothing represents the default value of a data type.
Though you don't have to assign anything to get the default value, so these two lines produce identical outcome:
Private m_ClientAreaCode As Char
Private m_ClientAreaCode As Char = Nothing
There's no concept of "empty character" in VB.NET. Char
is of fixed size, so you cannot make it empty.
If you want to initialize a char variable as null character explicitly:
Private m_ClientAreaCode As Char? = Chr(0)