Marty,
It depends (somewhat) on the mode you compile it in. In debug mode,
using the conditional operator will reduce your code profile. When checking
the IL, a simple function which had nothing but a conditional operator in it
(with some setup), next to the same function using an if statement, the
function with the if statement had 10 more lines of IL in it.
In release mode, the IL was virtually identical with the exception of
one line.
Now, what does this mean? Pretty much nothing. I would not get in a
tizzy over 10 lines of code in debug version being compiled by the JIT,
which is going to optimize it anyways, and probably produce similar code
with similar performance profiles.
To be honest, if someone told me that one was more performant over the
other, then I would laugh. I mean, it's VERY unlikely, and if there is a
difference as a result of this, it is going to be SLIGHT and most likely
insignificant.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Marty" <xm******@hotmail.com> wrote in message
news:acdxf.82576$6K2.51670@edtnps90...
Hi,
Does using the the conditional operator (?:) instead of the common "if"
statement will give a performance gain in a C# .NET 2003 application (even
in C# .NET 2005?).
What is the advantage of using it in C# other than typing shorter if ?
Thanks,
Marty