asp.net - Conditional C# Ternary Operator statement to execute methods with Void Return Type -
how can use coalescing operator choose method calls depending upon true or false value , follows:
- request.querystring=="new"? newpage() : oldpage() ;
- request.querystring=="black"? blackmonie(): request.queystring=="white"? whitemonie():tacs();
instead of common coalescing operator call using stoage variable follows: string s= color=="r"? "red" : "green";
it's not overly clear question, assume newpage()
, oldpage()
both void
methods.
so, can't use ternary operator you're proposing without getting lot of messy code returns actions need invoked.
and there seems little benefit in trying work built in if
, else
keywords pretty close want.
here suggested use of ?:
operator standard if
code:
request.querystring == "new" ? newpage() : oldpage(); if (request.querystring == "new") newpage(); else oldpage();
that's 7 characters difference.
i'd stick standard if
approach.
Comments
Post a Comment