Devlogs
understand the variables and types in programming
Posted June 06, 2020 by yassinealoui
#c# #coding #unity coding #learn coding #game development #variables #types #programming #code
what does it mean by
VARIABLE and TYPE ???
Variables are simply containers for storing data values(exp : names ,numbers ,characters..etc)
Now not all the barrels have the same color ,each color refer to a certain “TYPE” of data that the barrel is designed to store
For exemple :
1-green barrel can store integers(…-3,-2,-1,0,1 ,2,3..)
2-the red barrel can store text (words , paragraphs..)
3-blue barrel can store characters(‘A’,’B’…,’?’,’/’..’a’,’b’..)
----------- Analogy :
A BARREL means VARIABLE
The COLOR of the barrel means the TYPE of the variable
And now let rewrite these previous phrases :
1-the INT variable can store integers(…-3,-2,-1,0,1 ,2,3..)
2-The STRING variable can store text (words , paragraphs..)
3-the CHAR variable can store characters(‘A’,’B’…,’?’,’/’..’a’,’b’..)
-----------SYNTAX :
Now let try to code an example in c#
Before we dive into the syntax word I want to mention that each variable have a DISTINCT name for it. why ? imagine if your friend doesn’t have a name then how can you call him/her ?
creating a variable in c# language :( 2 steps)
Or you can mix the two steps in one line of code :
Now you are wondering “what the heck is that semi_colon in the end of every line of code ?”
the answer : is exactly like the full stop at the end of the sentence . the semi colon “;” means that the command(line of code) is done.
------other types of variables:
Boolean :
the variable of type Boolean can only store one of two values {true , false} (in lowercase ,yes there is a difference between lower and uppercase in programming)
Exp :
Now you will tell me : “hey wait ! aren't true and false words , and we said previously that variables that store text should have the type of string not Bool !
I ll answer and tell you :”brilliant question but true and false are not ordinary words they are KEYWORDS,”
-what are keywords ?
-simply they are predefined, reserved words used in programming that have special meanings in the programming language like :
-so what happens if I wanted to use the word true or false in my text ? I can’t?
-no you can ! the thing that differentiate the text words from the keywords is just the double quotes {“”} let ‘s see an exemple
Float :
type of a variable that stores a number that has a decimal place
Note :
=> the first is considered as integer and the second is considered as float(3.0)
----------------------------------------------------------------------------------------------------------------
CONCLUSION :
variables are just containers for storing
data ,each variable have a name and type and a value .
--------------------------------------------------------------------------------------------------------------
Note : you should initialize(assign a value to) your variable before using it or you will get this error message :” Use of unassigned local variable” or something like it.
In the next devlog we will take a look of some
operations and applications of the variables
If you have any questions feel free to post them in the comments and I ll be happy to answer them!
and if you liked this support me by following me
thank you for reading!!!