// The or statement in C# is ||
if (a == b || a == c)
{
// Do something
}
"c# 'or' is '||' and 'and' is '&&'"
// 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
}
//the or operator in c sharp is "||" (key to the left of 1 btw ;))
if(a = 0 || b = 0)
{
//a or b is 0
}
if (2 > 1 || 1 == 1)
{
// 2 is greater than 1 and 1 is equal to 1!
}
float numberOne = 1;
string stringOne = "one";
if (numberOne == 1 || stringOne == "one")
{
print("numberOne or stringOne = 1")
}
# 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);
(a == b || a == c) //Finally a question nobody's freakin' answered!
&& -> and
|| -> or
int x=20;
Console.WriteLine("----- Logic Operators -----");
Console.WriteLine(x > 10)
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);
}
}
}
&& And
|| OR
if (true || false) { //Checks if either side is true
Console.WriteLine("One is true");
}
if (false || false) {
Console.WriteLine("Both are false");
}
//Output:
//One is true