Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IIF In C#?
Message
From
17/03/2010 19:29:45
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Miscellaneous
Thread ID:
01455229
Message ID:
01455254
Views:
72
>>>>Any way to do this in C# like VFP's IIF()?
>>>>
>>>>
>>>>if (Checked)
>>>>{
>>>>    _CheckItemsCount++;
>>>>}
>>>>else
>>>>{
>>>>    _CheckItemsCount--;
>>>>}
>>>>
>>>
>>>
_CheckedItemsCount+=    (Checked) ? 1:-1;
>>
>>IMHO, this is harder to read than the original.
>
>Probably because you're not used to reading it :-}

For sure it's in the eyes - and experience - of the beholder.

The C/C++/C# conditional operator is so useful I'd bet it's widely implemented in other languages, too. But so is IF... etc.

It could be argued that for simple cases like this the *only* significant consideration is readability/maintainability. Any decent optimizing compiler (JIT or otherwise) will probably spit out identical opcode for those two snippets.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform