How to choose a single value if true or false in C #?

I am new to C #. Is there any function for this? (can anyone tell me what to call it?)

For instance:

 string str = boolVar: "trueA" || "falseA";// if boolVar = true => return string trueA

or

 var abb = booVar: "stringIfTrue" || 3.14; //if boolVar == false => return double 3.14
+4
source share
2 answers

As Tim showed , the first case can easily be done with a conditional operator (sometimes also called a ternary operator).

If you really really want the second job to work, you can use the .NET dynamictype :

dynamic abb = booVar? "stringIfTrue" : (dynamic)3.14;

You must specify at least one of the last two operands on (dynamic).

Example: https://dotnetfiddle.net/

+3
source

:

string result = boolVar ? "stringIfTrue" : "stringIfFalse";
+6

Source: https://habr.com/ru/post/1653452/