C# – Conditional Ternary / Comparision and Logical Operator

As usual today as well I will be showing operators in C#

Shortcut for evaluating  an expression  and returning a result;

Conditional Ternary Operator

result = ( a == b) ? "Equal" : "Not Equal";

Here we are saying that if a and b is equal, evaluate first expression which is “Equal”, if not then evaluate “Not Equal”

Comparision and Logical Operator

Comparision operators used for conditional statements.

For example ;

== (equal)

!= (not equal)

(greater than=

(greater than or equal)

!someBoolenValue (means NOT is true)

Logical Operators

used to combine multiple operations / evaluate

&& (and)

|| (or)

combine with paranthesis () for order of presence

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: