As previously stated in our lessons, as your programs will become more and more complex, they will perform a set of instructions when a condition is True, and another one when is False. When your program executes a conditional processing, you will be testing a condition with If.… Read more
Archive for the ‘Introduction’ Category
Testing a condition with If
Saturday, January 7th, 2017Representation of True and False values
Saturday, January 7th, 2017A few lessons so far dealt with conditional processing, displaying a result when a condition is true, and another when it is false. When working with conditional processing, it is important to understand the representation of True and False values in C#.… Read more
Conditional processing
Saturday, January 7th, 2017Now that we are done with data types, we can finally start learning about doing something useful with that data. Conditional processing is one of the most basic forms of allowing your programs to perform an useful action.
As you noticed, all the programs presented so far in our lessons started the execution with the Main method, and continued subsequently with the following instructions.… Read more
Conversion to type String
Saturday, January 7th, 2017The first kind of conversion to type string is the implicit type converting. Whenever you concatenate a string and another type which is not of type string, the .NET runtime will convert the second type to string, on the fly, in behind, without you knowing it.… Read more
Explicit type conversion
Friday, January 6th, 2017Explicit type conversion basically means “I know what I am doing, so let me covert this into this, because I know it will work”. It is used whenever there is a possibility of data loss. For instance, when converting from ANY real number type into an integer, there is ALWAYS a loss of data, because integers cannot store fractional parts.… Read more
Implicit type conversion
Friday, January 6th, 2017As we discussed in the last lesson, implicit type conversion (hidden conversion) is only possible when there is no risk of any data loss during the transformation (for instance, when converting a lower range number, like an int, to a higher range number, like a long).… Read more
Casting and type conversion
Friday, January 6th, 2017Other operators
Friday, 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 (ternary) operator
Friday, 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
Friday, 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