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:

  1. request.querystring=="new"? newpage() : oldpage() ;
  2. 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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -