Null (In C #) Vs Nothing (at vb.net)
In your code, VB guesses that you are comparing Strings, since one of the operands is String. In comparison it is String Nothingequivalently empty String "". Then it performs a comparison of the values ββthat it returns True.
Use Isto compare links:
Console.WriteLine(Nothing Is "") '=> False
, Nothing vb.net null #
Visual Basic Nothing:
; , . .
Microsoft, , Nothing vb.net default(T) # .
Dim isSomething As Boolean = Nothing ' = False
Dim amount As Integer = Nothing ' = 0
Dim value As String = Nothing ' = null (notice not empty string!)
, , /
Dim value As String = Nothing
If value.Equals("") Then ' will throw NullReferenceException
End If
Nothing "" "=" vb.net, Nothing null
Visual Basic String:
, , . . , Unicode . , , .NET Framework. ".
vb.net String.Equals Is.
, null, Nothing . , .
, Nothing vb.net default(T) #
# null VB.NET?
# null , (String), # null vb.net, Nothing.(null == default(String))
. , , . , .
, Nothing VB null #, , ( Nothing). MSDN, null . - VB, # , VB, .
, VB, . VB Nothing , "" MSDN:
Nothing 0. Nothing "" ( ).
, VB? , VB Nothing ( , = , ). null #, . default(T) #. =, VB , Nothing . :
VB Nothing null:
Console.WriteLine(s Is Nothing) //C#: (s == null)
VB Nothing default(T), :
Dim s As String = Nothing //C#: string s = default(string);
Dim i As Integer = Nothing //C#: int i = default(int);
, , VB # . , . VB # true :
Console.WriteLine(5.0 = 5) //C#: (5.0 == 5)
, VB # , . , "" null VB, #. , VB. , , :
Console.WriteLine(s = Nothing)
Console.WriteLine(s = "")
, VB Nothing "" . # , :
Console.WriteLine(s == null && s == "")
, VB , # , . . , , # , ==:
Console.WriteLine(s == null)
VB =, , Is:
Console.WriteLine(s Is Nothing)
, VB , # . , , :
Console.WriteLine(string.IsNullOrEmpty(s))
.
, VB.NET :
Dim myText As String = Nothing
Dim myInt As Integer = Nothing
Dim myFloat As Single = Nothing
Dim myBoolean As Boolean = Nothing
Dim myDate As DateTime = Nothing
ILSpy, # :
string myText = null;
int myInt = 0;
float myFloat = 0f;
bool myBoolean = false;
DateTime myDate = DateTime.MinValue;
VB.NET Nothing literal, .
From # default(Type) VB Nothing