java - Ternary operator usages? -


i know ternary operator used of doing variable assignment after evaluating logical condition.

so:

string s = (logicalvariable) ? "hello" : "bye, bye"; 

or,

int x = (5<3) ? 10 : 100; 

would usage examples, right?

but if idon't want variable assignment set sentence or piece of code, example:

if (inventario.containskey(item))         return inventario.get(item);     else return integer.min_value; 

can these lines writen in one line expression, using ternary operator?

this should work:

return inventario.containskey(item)? inventario.get(item); integer.min_value; 

the first part need evaluate boolean


Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

tags - Jquery Mixitup plugin help prevent handlers being destroyed -

c# - Delving into the world of XML (Windows Phone) Error I dont understand (The ' ' character, hexadecimal value 0x20, cannot be included in a name.) -