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 :: Click an HTML link inside a WebBrowser Control 
Csharp :: C# return dictionary string/integer from comparison of List and Array 
Csharp :: Unity android plugin callback 
Csharp :: how to change something in the window using a thread wpf 
Csharp :: jtoken null or exists c# 
Csharp :: ActionExecutingContext result response return objects 
Csharp :: how to pass value to anothe form c# winform 
Csharp :: c# propertyinfo indexof 
Csharp :: json.net jobject replace value 
Csharp :: static variables 
Csharp :: creating an object 
Csharp :: opération inter-threads non valide 
Csharp :: How to set a Printer Port in C# on a specified Printer 
Csharp :: c# statements 
Csharp :: visibility bound to radio button wpf 
Csharp :: Debug output to console and a log 
Csharp :: Xamarin Forms iOS Picker done 
Csharp :: check null type 
Csharp :: Query mongodb collection as dynamic 
Csharp :: c# creat pen 
Csharp :: check which activity in focus in android 
Csharp :: how to set the forgound color of listitems in c# 
Csharp :: how to print a word in C# 
Csharp :: two question marks together mean in C# 
Csharp :: How to add a dynamically created form to a new tab in Syncfusion WinForms TabControlAdv? 
Csharp :: CS0176 
Csharp :: Enum into table C# 
Csharp :: design pattern for so many conditions c# 
Csharp :: make tooltip disappear c# 
Csharp :: windows form button border color 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =