-5

About Me: I am new to C#.

So i found this code on Microsoft!

int a, b, c;
a = 7;
b = a;
c = b++;
b = a + b * c;
c = a >= 100 ? b : c / 10; //This Line Is Confusing
a = (int)Math.Sqrt(b * b + c * c);

Can Someone explain me why the ? : are used There?

What's the use of the "? :"

user14273848
  • 37
  • 10

1 Answers1

1

?: is conditional operator in c#

condition ? consequent : alternative

The condition expression must evaluate to true or false. If condition evaluates to true, the consequent expression is evaluated, and its result becomes the result of the operation. If condition evaluates to false, the alternative expression is evaluated, and its result becomes the result of the operation. Only consequent or alternative is evaluated.

Reference

Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48