-
Hello, and welcome to How To: Beginner Programming,
-
a multi-part guide to your first steps into the world of programming.
-
In each of the following episodes, I'll be demonstrating the
basic principles of programming,
-
from creating your first application, to developing your own objects.
-
In the previous episode, we talked about Hello World,
-
setting up your environment, and outputting text to the screen.
-
In this episode I'll be explaining what variables are,
-
the types of variables available for use,
-
and some arithmetic that can be performed on them.
-
Right here I've got all the types of primitive variables...
-
These are all variables; the most basic types of variables.
-
I'm showing an example of how to declare them here...
-
When you declare something,
-
you need to know the type of variable to use first.
-
For example, an integer...
-
You give it a name, and then a value.
-
That's just assigning 293,193 to the variable.
-
I've got an example of all the upper and lower bounds
of each of these types.
-
Bytes are 1 byte unsigned integers,
-
I'll run the program so you can see.
-
Byte is unsigned. So that's 0 to 255.
-
Short is a two byte signed integer,
-32,000 up to 32,000.
-
Integer is a four byte signed integer,
from ~-2 billion to ~2 billion.
-
Long is...
-
~-9 centillion to ~9 centillion.
-
So, they're getting a bit big here!
-
Double is eight byte floating point numbers.
-
So, for example, 1.7 is a double, or 9.8, and so on.
-
Doubles range from
~-1.79×10^308 to ~1.79×10^308
-
Doubles have a huge range!
-
Decimals are sixteen byte decimal numbers,
and they range from ...
-
I'm not even going to attempt to break that down...
-
It can handle both decimals and whole numbers.
-
Boolean is a true/false value, or 1/0.
-
And they can be assigned like this...
-
Boolean, then a name, then a value.
-
Char is a character, which represents a single unicode character.
-
You can view all of these on the ASCII sheet,
-
basically, anything you can type on the keyboard,
-
but only one character.
-
For example, a space, or a question mark.
-
String are made up of a sequence of chars (or characters),
-
I've just assigned "Hello" to this one,
but they can hold any string of characters.
-
String accepts absolutely anything on the keyboard as well.
-
Those are all of the data types,
-
I'm now going to show you some math you can do with them.
-
Now, all numeric values can be used in arithmetic calculations.
-
For example, the decimal value...
-
the decimal value of 10.2...
-
can be added to the integer value of 2.
-
And if we write this out to the console...
-
and cast the decimal to a decimal,
-
because the program thinks it's a double,
-
so we put the little 'm' at the end to make sure
the program knows it's a decimal.
-
And it will give us...
-
12.2
-
Arithmetic can also be used on characters.
-
The program uses the numeric value of a character in the arithmetic.
-
For example, if we have the character 'Z', and add 2 to it...
-
the ASCII value for the 'Z' will be used...
-
this is called casting.
-
Casting will take whatever variable type comes out of this
and cast it as another type.
-
So this will go two places through the ASCII table from 'Z',
-
which is a backslash.
-
So that's arithmetic with chars.
-
Chars can also be added to strings. For example...
-
These double quotes are for assigning strings,
-
so a string can also be a single char (character).
-
If we want to make sure it's a char we're adding to it,
-
we use single quotes.
-
It still has the same effect, but the difference is:
-
a string uses double quotes, and a char uses single quotes.
-
There are some cool little functions you can do with primitive variables.
-
(Plus plus) will increment it by 1.
-
When we output it again, the answer will be 2.
-
(Minus minus) will decrement it by 1.
-
This value of "test" can be changed (reassigned) like this...
-
We can assign it to the variable name (the old value)
plus 10.
-
We assigned it there, then we output 1.
Increment it by 1 = 2. Decrement it by 1 = 1.
-
Add 10 = 11.
-
There are other cool things, but that's the basic stuff.
-
You can also do the same thing with minus,
and there are some shorthand ways as well.
-
Plus equals (+=) is [increment and reassign].
-
That's all the basics when it comes to primitive variables
and arithmetic.
-
So, this has been the second part of How To: Beginner Programming.
-
More parts will be released shortly,
-
again I'll leave a gap between videos to allow you to
ask any questions you might have,
-
and I'll answer them in the next video.
-
I only had one question (last video), and that was,
-
why do I use C# over another language?
-
And that's because C#, I think, is a nicer language to begin with
-
than Visual Basic.
-
Because Visual Basic teaches awful practices,
-
and the structure of the code can be awkward.
-
If you go from Visual Basic to another language,
-
which you probably would,
-
then you carry over some bad practices.
-
C++ is incredibly involved when you get into arrays,
-
and we haven't gotten to arrays yet,
-
but in C++ you're accessing pointers in memory,
whereas C# handles all of that background stuff for you.
-
In C++ you have to handle it all yourself.
-
That's why I picked C#.
-
Thanks very much for watching!
-
Again, leave any questions in the comment section below.
-
See you next time for episode three!