newbie question on C#

  • Thread starter Thread starter Danny Ni
  • Start date Start date
D

Danny Ni

Hi,

I am looking for a function that will give me one value if a condition is
met, other value if not. I vaguely remember in C there is something like
this: (a>b? a,b)

Is there anything similar in c#?

TIA
 
Danny Ni said:
I am looking for a function that will give me one value if a condition is
met, other value if not. I vaguely remember in C there is something like
this: (a>b? a,b)

Is there anything similar in c#?

It's exactly the same in C#.

int intVar;
bool boolVar;

intVar = boolVar ? 1 : 2;

will set intVar=1 if boolVar is true, intVar=2 if it isn't.

-mdb
 
Danny Ni said:
I am looking for a function that will give me one value if a condition is
met, other value if not. I vaguely remember in C there is something like
this: (a>b? a,b)

Is there anything similar in c#?

Yes:

a > b ? a : b

(It's the same syntax as in C, by the way.)
 
Back
Top