// Logical operators are a way for us to make our programs
// more efficient and clean to read.
// instead of a lot of if statements inside eachother
// logical operators allow us to check a couple of boolean expressions
// in a single if statement
// We have 3 logical operators: not (!), and (&&), or (||)
// let's see an example of them being used.
int num = 25;
bool isNumEven = num % 2 == 0;
// Not operator (!)
if (!isNumEven){
Console.WriteLine("not operator");
// if the value of the boolean variable/expression is false
// the not operator will make the if statement true basically
// like it's flipping the values
}
// And operator (&&)
if (num - 5 == 20 && Math.Sqrt(num) == 5){
Console.WriteLine("And operator");
// only if both expressions are true the if will return
// true and run the code written inside it.
// it's enough for one expression to be false for the entire thing
// to be false
}
// or operator (||)
if (num % 10 == 0 || num % 10 == 5){
Console.WriteLine("Or operator");
// if only one expression is true the if will return
// true and run the code written inside it.
// but if all expressions are false the if will return false
}
# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
int x=10, y=5;
Console.WriteLine("----- Logic Operators -----");
Console.WriteLine(x > 10 && y < 10);
int x=15, y=5;
Console.WriteLine("----- Logic Operators -----");
Console.WriteLine(x > 10 || 100 > x);
/* && would work only if both is true for example */ bool a = 1==2 && 1=< 2; // would be false
/* but if they are both true it would be true */ bool a = 1==1 && 1==1; // would be true
int x=20;
Console.WriteLine("----- Logic Operators -----");
Console.WriteLine(x > 10)
using System;
namespace Operator
{
class AssignmentOperator
{
public static void Main(string[] args)
{
int firstNumber, secondNumber;
// Assigning a constant to variable
firstNumber = 10;
Console.WriteLine("First Number = {0}", firstNumber);
// Assigning a variable to another variable
secondNumber = firstNumber;
Console.WriteLine("Second Number = {0}", secondNumber);
}
}
}
using System;
namespace Operator
{
class LogicalOperator
{
public static void Main(string[] args)
{
bool result;
int firstNumber = 10, secondNumber = 20;
// OR operator
result = (firstNumber == secondNumber) || (firstNumber > 5);
Console.WriteLine(result);
// AND operator
result = (firstNumber == secondNumber) && (firstNumber > 5);
Console.WriteLine(result);
}
}
}