Still think Ternary operators are evil?

OK, I’ve seen a lot of the VB guys complaining that using the ternary operator (which VB.NET just got as of 3.5) makes the code unclear.  To which I’ve said said, and continue to say, “Yes of course, if used incorrectly.”

But, this post, over at ASP.NET without ASP.NET shows a pratical use of the ternary operator and shows that it can be a lot more clear than multiple if/else if statements.


Now, we all know that a case statement would be preferred to multiple if/else if statements WHEN THAT IS POSSIBLE.  But, sometimes your if/else if is either not comparing against the same value, or is comparing multiple values.  In both cases, a switch statement will not work, or be as clear as this example of the ternary operator.


Other Related Items:

AXIOM 32MB DRAM Memory ModuleAXIOM 32MB DRAM Memory ModuleRAM Module Cisco MSR Catalyst 8500 Series AXCS-ASP-32M www.axiommemory.com 2 x 16 MB Lifetime SIMM Axiom Memory Solutions 32MB DRAM Memory Module 32 MB Axiom DRAM
ASP.Net Essential TrainingASP.Net Essential TrainingThousands of businesses have used ASP.NET to build
Active Server Pages (ASP)/Visual Basic (VB).NET -  Instructor-based Video Training BundleActive Server Pages (ASP)/Visual Basic (VB).NET - Instructor-based Video Training BundleInteractive Instructor-Based Active Server Pages (ASP)/Visual Basic (VB).NET Bundle Video Training Course on DVD-ROM. Computer Based Training (CBT) a... Read More >

If you're new here, you may want to subscribe to the mailing list to get notifications of new post and a virtual tour of past topics. Thanks for visiting!

Most Commented Post

Comments are closed.

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor