‫Welcome back.
‫In this video, we're going to check out data, types and variables.
‫So pretty much the process of storing data in a variable.
‫Now let's dive right into it.
‫First of all, variables can be pretty much declared outside of a method, but also inside of a method.
‫And if we have a variable here in this example, it's an integer variable, so it's a variable of type
‫int and we have given it the name age and assigned the value 15.
‫So we declared a variable called age of type int and defined the value of 15.
‫So we assigned 15 as its value.
‫So this is a variable of type integer and if we want to use it now, we simply have to use the name
‫of that variable and it will pretty much output 15 in this case.
‫So console right line gives us the age and the age was 15.
‫So whatever value we assign here will also be used in here.
‫So we pretty much stored the data and now we can call it any time we want.
‫And we are inside of this main method here, which is the starting point of our program.
‫And by the way, we are within a class here.
‫So the class is called lecture and that's the general structure of a C sharp type of code.
‫So you have a class, then you have the main method, which is the starting point of your program where
‫everything begins.
‫All right, now let's have a look at this.
‫What we can see here is that the variable now has the value of 20, because we started off with 15,
‫as we did before, but now we assigned a new value to it later on.
‫And that's very common.
‫That happens a lot.
‫And as you can see, we assign a new value of 20.
‫And now if we print out using this console right line statement, then suddenly we will get the value
‫of 20 and not the value of 15, which we had before then an example with no value.
‫So in this case we have an age and we have not assigned a value in this case.
‫So it pretty much means that the default value will be assigned at the default value is zero.
‫It's different than in other programming languages there.
‫The default value will be null, which pretty much means empty, but in this case it's zero.
‫So if we now use console right line age, the output will be zero.
‫So what if we declare such a variable within a method?
‫Then it's a different story because now this variable end h will only be available within that particular
‫method where it was declared in.
‫And if we want to use H in another method now, it will not be visible.
‫So we cannot use it there and it will result in errors.
‫So that's something that you have to keep in mind.
‫It's important where you declare your variable if you declare it outside of a method.
‫So here at the top, just within the class lecture, in this case, it will be usable in multiple different
‫methods, but in this case it will only be usable in the method main because it's declared in the method
‫main.
‫But there are more than just the type.
‫We have checked out the type now, but there are other data types as well.
‫Let's talk about the different data types real quick.
‫So first of all, we have this byte which stands for Signed Byte and we call it X and we assigned a
‫value of 120.
‫Now signed byte can consist of values between 128 minus up to 127.
‫So in total, 256 different values.
‫And this is a very small amount of data.
‫It will only store a little bit of data, but that at the same time means that this data type doesn't
‫need a lot of storage, which is great if you want to write very performant software.
‫Now there is the short keyword as well, which is another primitive data type.
‫And in this case it can store whole numbers between -32,767 and 32,767.
‫Then we have the integer which can store values from -2,147,000,000 and some change up to plus 2,147,000,000
‫and some change.
‫So again, only whole numbers.
‫And as you can see, the numbers get bigger and bigger.
‫But what if you need a very big number to store?
‫Well, then you would use long.
‫And as you can see, long can store a very long number.
‫And in this case, from -9,000,000,000 billion up to plus 9,000,000,000 billion.
‫And I'm just using billion billion because I'm not sure what exactly the term for such a huge number
‫would be.
‫So if you need big numbers, that's the way to go.
‫Then it's the question, of course, when to use each of these data types, because we have looked in
‫short byte, short integer long.
‫When would you use which one?
‫Well, pretty much use the smallest data type your value fits in.
‫So the smaller the data that you want to store, so the smaller the value, the smaller the data type
‫should be that you're using.
‫So as byte for very small numbers, short for longer numbers, integer for quite long numbers and long
‫for super long numbers.
‫Then what if you want to use floating point values?
‫Well, there are three data types which you can use for that.
‫One of them is the float data type.
‫And in this case, we assign a value of 99.99.
‫And as you can see, we have to add this F here, which tells C-sharp that we're talking about a float
‫value.
‫So if we don't use this F, then it will consider it as a double value and we will receive an error.
‫So it's important to add the F here and we will look into double in a second as well.
‫So this allows decimals and range from 1.5 times ten by the power of -45 to 3.4 times ten by the power
‫of 38, you have a seven digit precision here.
‫So not super precise, but still good enough for most cases.
‫Then we have the double.
‫And the only difference is that here we have a 15 digit precision.
‫So if you need a higher precision and a higher range, then you would use double.
‫And as you can see, there is no F here and no D at the end.
‫This pretty much means that we are using a double here.
‫On the right hand side we have a double and on the left hand side we declare a double.
‫So this code works.
‫If you add an F here now, then you will have the same problem as if you had left out the F when creating
‫a float.
‫So you have to be precise here.
‫If you need even more precision and 28 digit precision, then you would use decimals.
‫So the data type decimal again in primitive data type, but a lot more precise when to use flow double
‫or decimal.
‫Well, the same story.
‫The smaller the value is, the smaller the data type should be.
‫So it has also to do with performance.
‫So if you want to create graphic libraries or if you want to write something that has high demands for
‫processing power, for example, in video games, then you would use float.
‫This is also used for physics in video games, so then Float is good enough in most real world examples.
‫Then you would use double except for money calculations and that's where you would use decimal.
‫So it's mostly used in financial applications where you need the highest level of accuracy.
‫Now there are other data types as well, primitive ones, and there is this boolean which is similar
‫to a switch which can only have two values.
‫So it can either be true or it can be false.
‫Nothing else.
‫Only those two.
‫Then we have the chart or character data type and it will only contain one single letter.
‫And in order to assign something, you need to use single quotations here.
‫So single quote start single quote ends and allows a single character literal or unicode.
‫So here you can store any type of Unicode in here.
‫And then if you need a longer text consisting of multiple different characters, then you would use
‫a string.
‫And you can see here we are using the double code.
‫So this is pretty much used for text and allows multiple letters and unicode in here.
‫Now let's start coding and dive right into it.
‫Oh, and don't forget to rate this course, please.