Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IIF In C#?
Message
De
17/03/2010 19:29:45
 
 
À
17/03/2010 18:17:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01455229
Message ID:
01455254
Vues:
73
>>>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform