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

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...