Basicly I agree with Richard and Jochen.
Because of the results of Karthik I made my own test because I couldn't believe those results.
I tested it with VB.Net and also with C#.Net with this Code-Blocks :
Dim myObject As Object = Nothing
Dim x As Boolean
Dim d1 As Date = Now
For i As Integer = 1 To 100000000
If (myObject Is Nothing) Then x = True
Next
Dim d2 As Date = Now
For i As Integer = 1 To 100000000
If (Nothing Is myObject) Then x = True
Next
Dim d3 As Date = Now
Dim ts1 As TimeSpan = d2 - d1
Dim ts2 As TimeSpan = d3 - d2
object myObject = null ;
bool x = false;
System.DateTime d1 = System.DateTime.Now;
for (int i = 1; i <= 100000000; i++)
{
if ((myObject == null))
x = true;
}
System.DateTime d2 = System.DateTime.Now;
for (int i = 1; i <= 100000000; i++)
{
if ((null == myObject))
x = true;
}
System.DateTime d3 = System.DateTime.Now;
TimeSpan ts1 = d2 - d1;
TimeSpan ts2 = d3 - d2;
These are my results (by doing the compare 100 Million times :
Compare Timespan with VB Timespan with C#
myObj (assigned) to Nothing / Null 0,2390137 seconds 0,2808005 seconds
Nothing / Null to myObj (assigned) 0,3090174 seconds 0,2808006 seconds
myObj (not assigned) to Nothing / Null 0,3588006 seconds 0,3900007 seconds
Nothing / Null to myObj (not assigned) 0,2962005 seconds 0,2744006 seconds
Int-Constant to Integer-Variable 0,2652005 seconds 0,2652005 seconds
Int-Variable to Integer-Constant 0,2652005 seconds 0,2652005 seconds
I think that an average over 100 Million cycles says much more that an only 1 cycle-test (sorry Karthik) which shows different values with a big range.
But for me it was also very interesting that there is a difference (by handling Objects) between VB and C# ...