Presentation on logical_operators
Transcript of Presentation on logical_operators
1
Logical Operators
ICT Level VCOT - Jaffna
S.Sakthybaalan
05/01/20232
Operator An operator is a symbol that tells the compiler to perform
specific mathematical or logical manipulations.
C# is rich in built-in operators and provides the following kinds of operators:
Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators
05/01/20233
OperatorsArithmetic Operators
Relational Operators
Bitwise Operators
Assignment Operators
Misc Operators
Logical Operators
05/01/20234
Logical Operators (Conditional Operators) Logical operators allows you to combine multiple
conditions.
These operators involves at least two conditions and the final Boolean result is determined by the operator being used.
AND
OR
XOR
NOT
Logical Operators
05/01/20235
Operand and Operators In all computer languages, expressions consist of two types of
components: operands and operators.
Operands are the objects that are manipulated.
Operators are the symbols that represent specific actions. example:
5 + x Note: All expressions have at least one operand.
operator
operands
05/01/20236
AND Operator (&&) The AND operator is used to compare two Boolean values.
It returns true if both of the operands are true.
a b Result (AND)
0 0 00 1 01 0 01 1 1
0 – false
1 - true
05/01/20237
AND Operator in Programmingname = "Steven";
password = "Steven123"; // evaluating both expression and returns true if all are true. if (name == "Steven" && password == "Steven123")
{ MessageBox.Show("Login Successful");}
else
{ MessageBox.Show "Unauthorised access");
}
05/01/20238
OR Operator (||) The OR operator is similar to AND, as it is used to
compare two Boolean values.
The OR operator returns true if either of the operand(s) are true.
a b Result (OR)
0 0 00 1 11 0 11 1 1
}0 – false
1 - true
05/01/20239
OR Operator in Programming
string username, password; if ((username == "Steven" || username == “Clark")
&& (password == "Steven123")){ MessageBox.Show("Login Successful");}
else
{ MessageBox.Show("Unauthorised access");
}
05/01/202310
NOT Operator (!) The NOT operator is a unary operator, as it operates on a
single operand.
The NOT operator inverts the value of a Boolean value.
If the original value is true then the returned value is false; if the original value is false, the return value is true.
a Result (NOT)
0 11 0
0 – false
1 - true
05/01/202311
NOT Operator in Programmingname = "Steven";password = "Steven123"; // evaluating both expression and returns true if all are true. if ( !(name == "Steven" && password == "Steven123"))
{ MessageBox.Show("Login Successful");}
else{ MessageBox.Show("Unauthorised access. Aborting…");}
05/01/202312
XOR Operator (^) It returns false if the following condition matches:
(i) if both or all the expression returns true.
(ii) If both or all the expression returns false.
a b Result (XOR)
0 0 00 1 11 0 11 1 0
0 – false
1 - true
05/01/202313
XOR Operator in Programmingstring name, password;
name = "Steven" ;
password = "Steven123" ;
//it returns false because both expression match. if ((name == "Steven" ^ password == “Clark")
{
MessageBox.Show(“Access granted…");
}
else
{ MessageBox.Show (“Access Denied. Aborting…”);
}
05/01/202314