Natürlich kann dir das wer sagen. Hier zuerst die Variante (object is nothing) als Sourcecode:
Code:
Module Module1
Sub Main()
Dim muh As Object
Console.WriteLine(muh Is Nothing)
End Sub
End Module
Daraus resultiert folgender MSIL-Code:
Code:
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 13 (0xd)
.maxstack 2
.locals init ([0] object muh)
IL_0000: nop
IL_0001: ldloc.0
IL_0002: ldnull
IL_0003: ceq
IL_0005: call void [mscorlib]System.Console::WriteLine(bool)
IL_000a: nop
IL_000b: nop
IL_000c: ret
} // end of method Module1::Main
Was passiert hier? Im Grunde wird durch das ldnull eine Null-Reference auf den Evaluation Stack gelegt. ceq vergleicht darauf hin deren Integer-Werte. Sind beide Werte ident, dann ist das Object Nothing, andernfalls nicht.
Nun die Variante mit IsNothing(). Zuerst der VB.NET-Sourcecode:
Code:
Module Module1
Sub Main()
Dim muh As Object
Console.WriteLine(IsNothing(muh))
End Sub
End Module
Und jetzt wieder MSIL-Code, damit wir die Vorgänge dahinter sehen:
Code:
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 20 (0x14)
.maxstack 1
.locals init ([0] object muh)
IL_0000: nop
IL_0001: ldloc.0
IL_0002: call object [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue(object)
IL_0007: call bool [Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(object)
IL_000c: call void [mscorlib]System.Console::WriteLine(bool)
IL_0011: nop
IL_0012: nop
IL_0013: ret
} // end of method Module1::Main
Hier ist schön zu sehen, dass ein Object erstellt wird. Dieses Objekt wird der IsNothing-Methode übergeben, welche einen Boolean zurückgibt. Dieser Wert wird dann ausgegeben.
Das Endergebnis dieser Analyse kannst du dir sicherlich selbst ausmalen.