Tuesday, 24 August 2021

c#

 

What is the conditional operator?

The conditional operator ?:, commonly known as the ternary conditional operator, evaluates a Boolean expression, and returns the result of evaluating one of two expressions, depending on whether the Boolean expression evaluates to true or false.


Here's the basic form:

<evaluate this condition> ? <if condition is true, return this value> : <if condition is false, return this value>

Recap

You should remember the following about the conditional operator:

  • Use the conditional operator when you need to add branching logic inline.
  • Use the conditional operator when you need to return a value based on a binary condition ... return this when true, return that when false.

No comments:

Post a Comment

remove duplicates in an sorted array

  using System; public class HelloWorld {          public static void Main(string[] args)     {         int[] ar={2,2,3,3,4,6,6};          C...