Casting and type conversion generally refers to modifying a data type into another data type. In order to perform an operation on two data types, we need to convert both to the same data type. Type conversion if of two kinds: implicit and explicit.… Read more
Casting and type conversion
January 6th, 2017Other operators
January 6th, 2017Aside of the operators I have enumerated so far, there are a few other operators that are either too simple, too rarely used or too unimportant to create additional posts for them.
The . (dot) operator. We’ve used it quite a lot so far (remember Console.WriteLine?).… Read more
Conditional operator
January 6th, 2017Conditional operator is a bit harder to explain. It takes an expression which produces a Boolean result in order to determine which of two other expressions will be calculated and have its value returned as a result. Its sign is ?:.… Read more
Assignment operators
January 6th, 2017This is the simplest operator of them all. It’s expressed simply by the equal (=) sign. Assignment operators are used to assign (give) a value to a variable.
They can also be used in cascade. Lets have a look at simple and cascaded assignment:
1 2 3 |
string name = "John Doe"; int x, y, z; x = y = z = 3; |
One very important thing to always remember is NOT to confuse the assignment operator = with the comparison operator == (a very common programming mistake).… Read more
Comparison operators
January 6th, 2017Another kind of operators we have enumerated are the comparison operators. As their name suggest, comparison operators are used to compare operands. There are 6 comparison operators:
1 2 3 4 5 6 |
> greater than < less than >= greater than or equal to <= less than or equal to == equality != difference |
All of the above operators return a Boolean value (true or false).… Read more
Bitwise operators
January 6th, 2017Any programmer knows that computers can only process information represented by a series of binary numbers (1 and 0). This means that when we store the number 55 in memory of the computer, it actually stores a series of bits represented as 00110111.… Read more
Concatenator operator
January 6th, 2017Though we already used the concatenator operator quite a few times, we did not explain it yet. The concatenator operator (+) is used to join values of type string together.
As a side note, it is not necessary for both operands to be of type string.… Read more
Logical operators
January 6th, 2017Logical operators are quite simple, since they can only produce two outputs: true or false. The basic logical (Boolean) operators are AND (&&), OR (||), XOR (also called “Exclusive OR”, ^) and NOT (or negation, !).
I will show you a sample of the four logical operations and the results that they produce:
1 2 3 4 5 6 |
x y ! |
Decrementing operator
January 6th, 2017Decrementing operator is the complementary part of the incrementing operator. What applies to the incrementing operator, also applies for the decrementing one.
Obviously, the difference is in the syntax and behavior. Decrementing operator can be expressed in four ways, just like incrementing one:
1 |
--variable, variable--, variable -= 1, variable =- 1 |
The difference in behavior should be obvious and self-explanatory: instead of adding, we subtract.… Read more
Incrementing operator
January 5th, 2017One of the most used operations in programming is incrementing a variable’s value. Incrementing operator is composed of two plus signs: ++ (and has two forms), or a variation of the following two operators: += and =+.
Lets consider the following example:
1 |
variable = variable + 1; |
In the above example, we are assigning a variable the result of adding 1 to its own value.… Read more