Edit:
Added an example which can be done with the if-else statement but not the conditional operator.
Before the answer, please have a look of [Which is faster?] on Mr. Lippert's blog. And I think Mr. Ersönmez's answer is the most correct one here.
I'm trying to mention something we should keep in mind with a high-level programming language.
First off, I've never heard that the conditional operator is supposed to be faster or the equally performance with if-else statement in C♯.
The reason is simple that what if there's no operation with the if-else statement:
if (i > 0)
{
value += 2;
}
else
{
}
The requirement of conditional operator is there must be a value with either side, and in C♯ it also requires that both side of :
has the same type. This just makes it different from the if-else statement. Thus your question becomes a question asking how the instruction of the machine code is generated so that the difference of performance.
With the conditional operator, semantically it is:
Whatever the expression is evaluated, there's a value.
But with if-else statement:
If the expression is evaluated to true, do something; if not, do another thing.
A value is not necessarily involved with if-else statement. Your assumption is only possible with optimization.
Another example to demonstrate the difference between them would be like the following:
var array1=new[] { 1, 2, 3 };
var array2=new[] { 5, 6, 7 };
if(i>0)
array1[1]=4;
else
array2[2]=4;
the code above compiles, however, replace if-else statement with the conditional operator just won't compile:
var array1=new[] { 1, 2, 3 };
var array2=new[] { 5, 6, 7 };
(i>0?array1[1]:array2[2])=4; // incorrect usage
The conditional operator and the if-else statements are conceptual the same when you do the same thing, it possibly even faster with the conditional operator in C, since C is more closer to the assembly of the platform.
For the original code you provided, the conditional operator is used in a foreach-loop, which would mess things up to see the difference between them. So I'm proposing the following code:
public static class TestClass {
public static void TestConditionalOperator(int i) {
long value=0;
value+=i>0?2:3;
}
public static void TestIfElse(int i) {
long value=0;
if(i>0) {
value+=2;
}
else {
value+=3;
}
}
public static void TestMethod() {
TestConditionalOperator(0);
TestIfElse(0);
}
}
and the following are two version of the IL of optimized and not. Since they are long, I'm using an image to show, the right hand side is the optimized one:
(Click to see full-size image.)

In both version of code, the IL of the conditional operator looks shorter than the if-else statement, and there still is a doubt of the machine code finally generated. The following are the instructions of both method, and the former image is non-optimized, the latter is the optimized one:
In the latter, the yellow block is the code only executed if i<=0
, and the blue block is when i>0
. In either version of instructions, the if-else statement is shorter.
Note that, for different instructions, the [CPI] is not necessarily the same. Logically, for the identical instruction, more instructions cost longer cycle. But if the instruction fetching time and pipe/cache were also take into account, then the real total time of execution depends on the processor. The processor can also predict the branches.
Modern processors have even more cores, things can be more complex with that. If you were an Intel processor user, you might want to have a look of [Intel® 64 and IA-32 Architectures Optimization Reference Manual].
I don't know if there was a hardware-implemented CLR, but if yes, you probably get faster with conditional operator because the IL is obviously lesser.
Note: All the machine code are of x86.