Working with legacy code, I found I got are lot of statements (more than 500) like this
bool isAEqualsB = (a == b) ? true : false;
Does it make any sense to rewrite it like this ?
bool isAEqualsB = (a == b)
Or will be optimized at compile time ?
Thanks in advance,
Santi! =)
Ignore the performance – that’s so unlikely to be a bottleneck, it shouldn’t be what you think about until you’ve proved that it’s relevant with appropriate benchmarks.
I would absolutely care about the readability though – and from that point of view, I consider the second approach to be much better, and would certainly use it.
EDIT: In terms of optimization, it looks like the C# compiler doesn’t optimize it:
However, it’s not the IL that will matter of course – it’s what the JIT compiler does. Now even the difference in IL size may mean the difference between inlining and not…