C-SHARP - 2.8 Operators
Hello everyone and welcome to this new video. Today we will address the notion of operators. In C#, there are different types of operators. Arithmetic operators, comparison operators, assignment operators, logical operators and binary operators that we will see later because it is a more advanced notion. First, we will talk about arithmetic operators. Arithmetic operators are simply the operators used in mathematics. We have the + to add that we have seen in previous videos, the - to subtract, multiplication, division and there to finish what is called a modulo. Indeed, this operator is probably new and it will simply make it possible to recover the rest of a division. Then we have in the category of arithmetic operators, increment and decrement operators. ++ for incrementation and -- for decrement And they will allow you to add or decrease the value of a variable by 1, it is basically a shortcut of a = a + 1 or a = a – 1 as you can see in the example right here. Now let's move on to the comparison operators. The double equal will allow us to do an equality test between two variables. In a previous video, we saw that a simple = made it possible to assign a value to a variable. And in C# to find this notion of equality we will have to put 2 ==. Here in the example we compare whether variable a is equal to variable b. Then below, the! = the opposite is true. This operator will allow us to do an inequality test as we can see in the example, we test here if a is different from b. Then we have the decreasing operator who will compare if a is strictly larger than b Here if a is greater or equal to b. Since we have an equal in addition to the decreasing sign we lose this strictly higher condition and we give our program another opportunity to compare whether it is greater or equal. After we have the opposite, the ascending operator that will compare if a is strictly smaller than b, and finally it is the same as here but there we have the ascending operator that will check if a is smaller or equal to b Let's move on to the assignment operators, as you already know the simple equal allows you to assign a value to a variable. Then for the rest of the table, these are all roughly shortcuts of what you see in this column. When you write this way in your program, it's the same as writing this way. And finally to finish the logical operators. These operators will often be used when we insert conditions into our program. Let's take a cooking recipe to illustrate this notion. Double ampersets translated as "AND" will allow us to add a condition in addition to our first basic condition. That is to say, here, let's imagine our condition is as follows: if the preparation is ready then put in the oven. Thanks to the ampersands, we will be able to add another condition in addition to the one we have given here that will give if the preparation is ready and the oven is 180° so put in the oven. In addition, these 2 conditions must be met if we want our instruction to be carried out. In any case, we will discuss these things in detail when we approach the notions of conditions Then we have the WHERE operators represented by 2 pipes, which will allow us to have at least one of the conditions met to be able to execute the instruction. That is to say, if the preparation is ready or the oven is 180° you can put in the oven, it is no longer required to have the 2 conditions met to be able to carry out the instruction only one will suffice. And finally, we have the Not operator, represented by an exclamation point allowing us to have the inverse of a condition. Let's take up our condition that if the oven is at 180° by putting an exclamation point in front of this condition then we will get the opposite of our basic condition, which will give here "If the oven is not at 180°: Then put in the oven". Here I think I went around the operators, we will see these operators in detail as we progress, we will practice on them. In any case, I hope you liked this video and that everything was clear to you! I'll see you next time in a new video