Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# logical operators

// 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
}
Comment

and operator in c#

# 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);
Comment

or operator in c#

int x=15, y=5;
Console.WriteLine("----- Logic Operators -----");
Console.WriteLine(x > 10 || 100 > x);
Comment

logical operators in c#

int x=20;
Console.WriteLine("----- Logic Operators -----");
Console.WriteLine(x > 10)
Comment

C# Logical Operators

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);
		}
	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: C3 compare hour 
Csharp :: calculate textbox value c# 
Csharp :: This page contains six pages, created with MigraDoc and scaled down to fit on one page 
Csharp :: void on TriggerCollisionEnter2D 
Csharp :: AuthenticationTicket authenticationProperties C# .net 
Csharp :: what does focusbale do in listview WPF 
Csharp :: set time on audio source unity 
Csharp :: wpf binding to static property in code behind 
Csharp :: c#, get a embedded resx file 
Csharp :: c# check multiple variables for null 
Csharp :: c# yes no cancel dialog with icons 
Csharp :: erewt 
Csharp :: insert button in c# 
Csharp :: c# delay 1 second 
Csharp :: turnary operator c# 
Csharp :: how to if button pressed do something in c# 
Csharp :: sortdescriptions wpf 
Csharp :: how to populate a collection c# 
Csharp :: how to fill dictionary in c# 
Csharp :: to string c# fields 
Csharp :: générer un nombre aléatoire en c# 
Csharp :: chrome devtools capture all styling an element uses 
Csharp :: how do I write to a csv file from c# using entity framework 
Csharp :: last word of string to uppercase c# 
Csharp :: linq cheat sheet 
Csharp :: c# check if pdf is protected without password 
Csharp :: system.collections.generic.list 1 system.int32 c# 
Csharp :: sqlite dapper bulkcopy 
Csharp :: get path revit link unloaded 
Csharp :: Last N lines from file 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =