Notes for You:: Logical Operators in C#.
- are also known as logical connectives.
- are used to connect one or more relational expressions (or conditional expressions).
- They accept Boolean values as operands (i.e. true or false), on evaluation they yield the result either true or false.
- There are 3 logical operators available in C#. They are
Logical And Operator (&&):
- If both LHS and RHS operands are true then the result will be true, in all other cases the result will be false.
Logical Or Operator (||):
- If both LHS and RHS operands are false then the result will be false, in all other cases the result will be true.
Logical Not Operator (!):
- If the given operand is true, then the result will be false. Vice versa.
Example Code:
using System;
namespace LogicalOperatorsDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine((3 < 4) && (4 < 5)); // True
Console.WriteLine((3 < 4) && (4 > 5)); // False
Console.WriteLine((3 > 4) && (4 < 5)); // False
Console.WriteLine((3 > 4) && (4 > 5)); // False
Console.WriteLine();
Console.WriteLine((3 < 4) || (4 < 5)); // True
Console.WriteLine((3 < 4) || (4 > 5)); // True
Console.WriteLine((3 > 4) || (4 < 5)); // True
Console.WriteLine((3 > 4) || (4 > 5)); // False
Console.WriteLine();
Console.WriteLine(!(3 < 4)); // False
Console.WriteLine(!(4 > 5)); // True
Console.ReadKey();
}
}
}
Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
C# Tutorial 21 - Assignment Operators in C# Programming Language
[ Ссылка ]
Follow the link for previous video:
C# Tutorial 19 - Relational Operators in C# Programming Language
[ Ссылка ]
=========================================
C# Tutorials Playlist:-
[ Ссылка ]
=========================================
Watch My Other Useful Tutorials:-
C++ Tutorials Playlist:
[ Ссылка ]
Java Tutorials Playlist:-
[ Ссылка ]
C Programming Tutorials Playlist:
- [ Ссылка ]
C Practical LAB Exercises Playlist:-
[ Ссылка ]
=========================================
► Subscribe to our YouTube channel:
[ Ссылка ]
► Visit our Website:
[ Ссылка ]
=========================================
Hash Tags:-
#ChidresTechTutorials #CSharp #CSharpTutorial #CHash #CHashTutorial
Ещё видео!