Welcome to the logic in C sharp chapter.
In this chapter we're going to look at logic and understand logic generally.
And then we're going to look into how we can use logic in coding because it's really really important.
Because basically you want to make sure that the specific code is executed if a specific condition is
met.
And in order to achieve that, you need to understand Boolean expressions and logic in general.
So let's have a look at that.
So there is this thing called Boolean expressions.
And Boolean expressions are basically expressions that in the end either have a true or a false as a
value, which basically means either the condition is met or a condition is not met.
And there is also the data type called bool or boolean, which basically allows us to store a value
that is either true or false, and the idea is that you execute in the end, something based on whether
something is true or something is false, and therefore we need to understand the logical operators
so they are and or not and XOR.
So you can basically combine different expressions to make a entirely complex logical condition that
evaluates whether something is true or false.
And then there is the idea of comparative operators as well, which compare if one thing is, for example,
bigger or greater than the other thing, or if it's the same, or if it's less than the other thing.
These are comparative operators.
We're going to look at those as well.
And then we can even combine these expressions.
So the logical operators and the comparative operators to make a very complex expression, which then
is going to only execute the code when we really want it, so to speak.
And the logical operators, as I said, are and or not.
And then there is this XOR as well, which is like not or and it's basically a combination of not and
or.
So you could say that it is not an individual one, but you can also consider it as an individual logical
operator.
So the and operator combines two conditions and evaluates true only if both are true.
Then there is the or operator which doesn't care which one of the two is true.
It will deliver true as the output.
And then there's the not operator, which basically negates the condition.
Evaluating to true if the original condition is false.
So we're going to look at that in specific coding examples, which will make it a lot easier to understand.
So here you have the three once again.
And the finally the XOR which I was talking about which evaluates to true when only one of the operands
is true.
Which basically means that if you have multiple operands, so one, two, and three, let's say and
two of them are true, then XOR would return false.
And if only one of them is true, then XOR will return true.
So that's the idea of XOR.
But it's a little complex to set up in C sharp in my opinion.
So we're really going to keep it simple with the others.
So I would say let's jump into coding examples because then it will make it a lot easier to understand.