Relational operators compare two values and return a boolean result.
1.Equality (==):
int a = 5;
int b = 10;
bool isEqual = (a == b); // false
2. Inequality (!=):
bool isNotEqual = (a != b); // true
3.Greater Than (>):
bool isGreater = (a > b); // false
4.Less Than (<):
bool isLess = (a < b); // true
5. Greater Than or Equal To (>=):
bool isGreaterOrEqual = (a >= b); // false
6. Less Than or Equal To (<=):
bool isLessOrEqual = (a <= b); // true
Logical operators combine multiple boolean expressions.
1 .AND (&&):
bool result = (a > 0 && b > 0); // true if both a and b are greater than 0
2. OR (||):
bool result = (a > 0 || b > 0); // true if either a or b is greater than 0
3. NOT (!):
bool isNotTrue = !(a > b); // true because a is not greater than b
4. XOR (^):
bool result = (a > 0 ^ b > 0); // true if only one of a or b is greater than 0
Combining Boolean Expressions
You can combine multiple boolean expressions to create complex conditions.
bool isAdult = (age >= 18);
bool hasPermission = true;
bool canEnter = isAdult && hasPermission; // true if both isAdult and hasPermission are true
Boolean Expressions in Conditional Statements
Boolean expressions are often used in conditional statements like if, else if, and while.
if (isAdult && hasPermission)
{
Console.WriteLine("You can enter.");
}
else
{
Console.WriteLine("You cannot enter.");
}
Boolean Expressions in Loops
Boolean expressions control the execution of loops.
int count = 0;
while (count < 10)
{
Console.WriteLine(count);
count++;
}
Relational operators compare two values and return a boolean result.
1.Equality (==):
int a = 5; int b = 10; bool isEqual = (a == b); // false
2. Inequality (!=):
bool isNotEqual = (a != b); // true
3.Greater Than (>):
bool isGreater = (a > b); // false
4.Less Than (<):
bool isLess = (a < b); // true
5. Greater Than or Equal To (>=):
bool isGreaterOrEqual = (a >= b); // false
6. Less Than or Equal To (<=):
bool isLessOrEqual = (a <= b); // true
Logical operators combine multiple boolean expressions.
1 .AND (&&):
bool result = (a > 0 && b > 0); // true if both a and b are greater than 0
2. OR (||):
bool result = (a > 0 || b > 0); // true if either a or b is greater than 0
3. NOT (!):
bool isNotTrue = !(a > b); // true because a is not greater than b
4. XOR (^):
bool result = (a > 0 ^ b > 0); // true if only one of a or b is greater than 0
Combining Boolean Expressions
You can combine multiple boolean expressions to create complex conditions.
bool isAdult = (age >= 18); bool hasPermission = true; bool canEnter = isAdult && hasPermission; // true if both isAdult and hasPermission are true
Boolean Expressions in Conditional Statements
Boolean expressions are often used in conditional statements like if, else if, and while.
if (isAdult && hasPermission) { Console.WriteLine("You can enter."); } else { Console.WriteLine("You cannot enter."); }
Boolean Expressions in Loops
Boolean expressions control the execution of loops.
int count = 0; while (count < 10) { Console.WriteLine(count); count++; }
C# is primarily used on the Windows . NET framework, although it can be applied to an open source platform. This highly versatile programming language is an object-oriented programming language (OOP) and comparably new to the game, yet a reliable crowd pleaser.
The C# language is also easy to learn because by learning a small subset of the language you can immediately start to write useful code. More advanced features can be learnt as you become more proficient, but you are not forced to learn them to get up and running. C# is very good at encapsulating complexity.
The decision to opt for C# or Node. js largely hinges on the specific requirements of your project. If you're developing a CPU-intensive, enterprise-level application where stability and comprehensive tooling are crucial, C# might be your best bet.
C# is part of .NET, a free and open source development platform for building apps that run on Windows, macOS, Linux, iOS, and Android. There's an active community answering questions, producing samples, writing tutorials, authoring books, and more.
Copyrights © 2024 letsupdateskills All rights reserved