hi,
Someone told me that the order of null in a comparision would affect the performance of the statement.
he said that
if (null == someobject)
{
....
}
would yield in a slightly better perfomance than
if (someobject == null)
{
....
}
have anyone ever heared something like that
anynote or hint
thanks

the order of null in a comparision
Keith Boyd -MSFT
I also want 2 know abt this.
bcoz i also seen this type of null comparision in Microsoft Ado.Net 2.0 Sql batch update seminar.
MarkDuffy
Ah... I remember now some grizzled old C programmer who explained why he did this:
(doesn't apply to C# or Java or any modern compiler)
Apparently, some people always put the literal or null first in a comparison so that *if* they forgot to include two equals signs and used just one, then the compiler would complain because of course you can't assign to a literal or null.
The lengths people go through to work around compiler issues ....
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# Converter
Instant VB: C# to VB Converter
Instant C++: C# to C++ and VB to C++ Converter
Instant J#: VB to J# Converter
Clear VB: Cleans up VB code
Clear C#: Cleans up C# code
KCReed
This is definitely *not* the case for any modern compiler.
You'll meet a lot of people who mindlessly repeat an ancient performance tip that only applied to a specific long-past time period or a specific long-fixed compiler bug.
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter and VB to C++ converter
Instant J#: VB to J# converter
Clear VB: Cleans up VB.NET code
Clear C#: Cleans up C# code
viewpl
Kari Ko
well... I guess it depends on the way that the compiler 'see' a null reference, for example, 'null == instance' would be a little faster if the compiler compared each segment of the 'instance' with the null reference, what I assume that's not true...
I guess that if the first segment of the instance is different from null the compiler already returns false, leading the null == instance to the same path of the instance == null
in low level languages like assembly this would make a difference though