0

What is the difference between these 2? I am talking about performance and file size.

public String Method()
{
    if(condition) return "a"; else return "b";
}

and

public String Method()
{
    return condition ? "a": "b";
}

Which do you prefer and why? Same question for

(condition == false) and (!condition)

user2179088
  • 65
  • 1
  • 9

1 Answers1

2

Both Perform the same function, and are compiled to the IL in the same way . So the fact is the readability of your code. If you find the IF condition gives your code a better understanding and readability use that and the same goes for Ternary operators.

Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47