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

and in c#

/* && 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
Comment

logical operators in c#

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

C# Operators

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);
		}
	}
}
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 :: add list to list c# 
Csharp :: c# callback action lambda 
Csharp :: SieveOfEratosthenes 
Csharp :: c# obsolete class 
Csharp :: two linked list intersection 
Csharp :: unity get max occurrence in list 
Csharp :: fluent api 
Csharp :: print pdf in c# 
Csharp :: c# destroy function...unity 
Csharp :: c# make a automapper 
Csharp :: sealed method in c# 
Csharp :: c# convert date to oracle format 
Csharp :: rotation 
Csharp :: c# const 
Csharp :: how to change color of part from the text in textblock wpf 
Csharp :: C# Linq item index 
Csharp :: C# Blocks with statements 
Csharp :: c# window form align right bottom 
Csharp :: linq c# object except two lists 
Csharp :: how to generate random unique id in c# 
Csharp :: flat view player movement script 
Csharp :: c# selenium xunit testing 
Csharp :: pricipal permission attribute in c# 
Csharp :: sto playing audiosource 
Csharp :: discord embeds how to separate inline fields 
Csharp :: how to stream video from vlc in c# 
Csharp :: array in c# 
Csharp :: c# response.contenttype set filename 
Csharp :: console writeline 
Csharp :: wpf databinding 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =