we got two operators in C sharp we have five types of operators arithmetic comparison assignment logical and bitwise let's take a closer look at each of these operators we use arithmetic operators in computations where we are working with numbers so as you see in this slide we have add subtract multiply divide and remainder of division we also have two arithmetic operators called increment and decrement which are shortcuts or adding one or subtracting one from a variable so a plus plus is equivalent to a equals a plus one now with this increment and decrement operator there are two ways you can apply them you can use them as a postfix so in this example a is 1 and when we apply the postfix increment operator first the value of a is assigned to B so B is going to be 1 and then a is incremented by 1 so in this example after the second line is executed a is going to be 2 and B is going to be 1 now let's take a look at a different way of applying increment operator as a prefix so in this example in the second line first a is incremented by 1 and then it's assigned to B so after the second line both a and B are going to be 2 so be aware of this difference ok next comparison operators so we got equal which is indicated by double equal sign not equal greater than greater than or equal to less than and less than or equal to now what I want you to pay attention to in this list is that the testing for equality is accomplished by double equal sign and that's different from a single equal which is the Stallman operator Lex assignment operators so the most commonly used is the one with a single equal sign so here we set a to one pretty basic now look at the next four types of assignment operators addition assignment subtraction assignment multiplication assignment and division assignment let's see how they work for example addition assignment a plus equal 3 means add 3 to a so it's equivalent to writing a equals a plus 3 and the same rule applies to other 4 assignment operators logical operators are used in boolean expressions which are often used in conditional statements will get two conditional statements later in this course so a real-world example is where you have a condition and you want to make sure that condition and another condition both are true or maybe one of them is true so that's where you use a logical operator in c-sharp the logical end is indicated by double ampersand and the logical or is implemented by double vertical line we also have the not operator which is indicated by an exclamation mark and finally in here we've got the bitwise operators bitwise operators are often used in low-level programming like when working with windows api or in sockets or encryption explanation of these is beyond the scope of this course but if you're interested let me know and I write a blog post for you now what I want you to take away here is that the bitwise End is indicated by a single and percent whereas the logical and which we use in conditional statements is indicated by double ampersand same for bitwise or and logical or so remember the difference okay enough theory let's flip over to visual studio and see all these concepts in action 

Post a Comment

If you have any doubt please let me know

Previous Post Next Post