1 00:00:00,240 --> 00:00:01,050 ‫Welcome back. 2 00:00:01,080 --> 00:00:04,320 ‫In this video, we're going to check out data, types and variables. 3 00:00:04,410 --> 00:00:07,350 ‫So pretty much the process of storing data in a variable. 4 00:00:07,470 --> 00:00:09,370 ‫Now let's dive right into it. 5 00:00:09,390 --> 00:00:17,790 ‫First of all, variables can be pretty much declared outside of a method, but also inside of a method. 6 00:00:17,850 --> 00:00:24,990 ‫And if we have a variable here in this example, it's an integer variable, so it's a variable of type 7 00:00:24,990 --> 00:00:31,110 ‫int and we have given it the name age and assigned the value 15. 8 00:00:31,110 --> 00:00:38,550 ‫So we declared a variable called age of type int and defined the value of 15. 9 00:00:38,550 --> 00:00:41,220 ‫So we assigned 15 as its value. 10 00:00:41,220 --> 00:00:46,950 ‫So this is a variable of type integer and if we want to use it now, we simply have to use the name 11 00:00:46,950 --> 00:00:51,810 ‫of that variable and it will pretty much output 15 in this case. 12 00:00:51,810 --> 00:00:57,780 ‫So console right line gives us the age and the age was 15. 13 00:00:57,780 --> 00:01:01,560 ‫So whatever value we assign here will also be used in here. 14 00:01:01,560 --> 00:01:05,790 ‫So we pretty much stored the data and now we can call it any time we want. 15 00:01:06,030 --> 00:01:12,240 ‫And we are inside of this main method here, which is the starting point of our program. 16 00:01:12,240 --> 00:01:15,060 ‫And by the way, we are within a class here. 17 00:01:15,060 --> 00:01:21,090 ‫So the class is called lecture and that's the general structure of a C sharp type of code. 18 00:01:21,090 --> 00:01:26,490 ‫So you have a class, then you have the main method, which is the starting point of your program where 19 00:01:26,490 --> 00:01:27,570 ‫everything begins. 20 00:01:27,780 --> 00:01:30,840 ‫All right, now let's have a look at this. 21 00:01:30,870 --> 00:01:37,080 ‫What we can see here is that the variable now has the value of 20, because we started off with 15, 22 00:01:37,080 --> 00:01:41,760 ‫as we did before, but now we assigned a new value to it later on. 23 00:01:41,880 --> 00:01:43,380 ‫And that's very common. 24 00:01:43,380 --> 00:01:44,250 ‫That happens a lot. 25 00:01:44,250 --> 00:01:46,560 ‫And as you can see, we assign a new value of 20. 26 00:01:46,560 --> 00:01:52,950 ‫And now if we print out using this console right line statement, then suddenly we will get the value 27 00:01:52,950 --> 00:01:59,280 ‫of 20 and not the value of 15, which we had before then an example with no value. 28 00:01:59,280 --> 00:02:05,040 ‫So in this case we have an age and we have not assigned a value in this case. 29 00:02:05,040 --> 00:02:11,130 ‫So it pretty much means that the default value will be assigned at the default value is zero. 30 00:02:11,310 --> 00:02:14,520 ‫It's different than in other programming languages there. 31 00:02:14,550 --> 00:02:19,770 ‫The default value will be null, which pretty much means empty, but in this case it's zero. 32 00:02:19,770 --> 00:02:25,440 ‫So if we now use console right line age, the output will be zero. 33 00:02:26,160 --> 00:02:30,180 ‫So what if we declare such a variable within a method? 34 00:02:30,210 --> 00:02:38,520 ‫Then it's a different story because now this variable end h will only be available within that particular 35 00:02:38,520 --> 00:02:40,710 ‫method where it was declared in. 36 00:02:40,710 --> 00:02:46,260 ‫And if we want to use H in another method now, it will not be visible. 37 00:02:46,260 --> 00:02:49,500 ‫So we cannot use it there and it will result in errors. 38 00:02:49,500 --> 00:02:51,960 ‫So that's something that you have to keep in mind. 39 00:02:51,960 --> 00:02:56,820 ‫It's important where you declare your variable if you declare it outside of a method. 40 00:02:56,820 --> 00:03:04,110 ‫So here at the top, just within the class lecture, in this case, it will be usable in multiple different 41 00:03:04,110 --> 00:03:11,040 ‫methods, but in this case it will only be usable in the method main because it's declared in the method 42 00:03:11,040 --> 00:03:11,490 ‫main. 43 00:03:13,020 --> 00:03:15,360 ‫But there are more than just the type. 44 00:03:15,360 --> 00:03:18,960 ‫We have checked out the type now, but there are other data types as well. 45 00:03:18,990 --> 00:03:21,410 ‫Let's talk about the different data types real quick. 46 00:03:21,420 --> 00:03:27,990 ‫So first of all, we have this byte which stands for Signed Byte and we call it X and we assigned a 47 00:03:27,990 --> 00:03:29,460 ‫value of 120. 48 00:03:29,760 --> 00:03:38,760 ‫Now signed byte can consist of values between 128 minus up to 127. 49 00:03:38,760 --> 00:03:42,330 ‫So in total, 256 different values. 50 00:03:42,330 --> 00:03:45,750 ‫And this is a very small amount of data. 51 00:03:45,750 --> 00:03:52,380 ‫It will only store a little bit of data, but that at the same time means that this data type doesn't 52 00:03:52,380 --> 00:03:57,600 ‫need a lot of storage, which is great if you want to write very performant software. 53 00:03:57,990 --> 00:04:02,790 ‫Now there is the short keyword as well, which is another primitive data type. 54 00:04:02,790 --> 00:04:13,170 ‫And in this case it can store whole numbers between -32,767 and 32,767. 55 00:04:13,850 --> 00:04:24,650 ‫Then we have the integer which can store values from -2,147,000,000 and some change up to plus 2,147,000,000 56 00:04:24,650 --> 00:04:25,400 ‫and some change. 57 00:04:25,400 --> 00:04:27,560 ‫So again, only whole numbers. 58 00:04:27,560 --> 00:04:30,170 ‫And as you can see, the numbers get bigger and bigger. 59 00:04:30,170 --> 00:04:33,730 ‫But what if you need a very big number to store? 60 00:04:33,740 --> 00:04:35,660 ‫Well, then you would use long. 61 00:04:35,660 --> 00:04:39,050 ‫And as you can see, long can store a very long number. 62 00:04:39,050 --> 00:04:44,960 ‫And in this case, from -9,000,000,000 billion up to plus 9,000,000,000 billion. 63 00:04:44,960 --> 00:04:50,330 ‫And I'm just using billion billion because I'm not sure what exactly the term for such a huge number 64 00:04:50,330 --> 00:04:50,870 ‫would be. 65 00:04:51,170 --> 00:04:54,140 ‫So if you need big numbers, that's the way to go. 66 00:04:54,320 --> 00:05:00,530 ‫Then it's the question, of course, when to use each of these data types, because we have looked in 67 00:05:00,530 --> 00:05:03,260 ‫short byte, short integer long. 68 00:05:03,320 --> 00:05:05,690 ‫When would you use which one? 69 00:05:05,690 --> 00:05:10,730 ‫Well, pretty much use the smallest data type your value fits in. 70 00:05:10,730 --> 00:05:19,460 ‫So the smaller the data that you want to store, so the smaller the value, the smaller the data type 71 00:05:19,460 --> 00:05:20,570 ‫should be that you're using. 72 00:05:20,570 --> 00:05:26,990 ‫So as byte for very small numbers, short for longer numbers, integer for quite long numbers and long 73 00:05:26,990 --> 00:05:28,220 ‫for super long numbers. 74 00:05:28,670 --> 00:05:31,820 ‫Then what if you want to use floating point values? 75 00:05:31,820 --> 00:05:35,140 ‫Well, there are three data types which you can use for that. 76 00:05:35,150 --> 00:05:37,250 ‫One of them is the float data type. 77 00:05:37,250 --> 00:05:41,540 ‫And in this case, we assign a value of 99.99. 78 00:05:41,540 --> 00:05:49,730 ‫And as you can see, we have to add this F here, which tells C-sharp that we're talking about a float 79 00:05:49,850 --> 00:05:50,690 ‫value. 80 00:05:50,720 --> 00:05:57,680 ‫So if we don't use this F, then it will consider it as a double value and we will receive an error. 81 00:05:57,680 --> 00:06:01,970 ‫So it's important to add the F here and we will look into double in a second as well. 82 00:06:01,970 --> 00:06:11,380 ‫So this allows decimals and range from 1.5 times ten by the power of -45 to 3.4 times ten by the power 83 00:06:11,380 --> 00:06:14,030 ‫of 38, you have a seven digit precision here. 84 00:06:14,030 --> 00:06:18,530 ‫So not super precise, but still good enough for most cases. 85 00:06:18,830 --> 00:06:20,090 ‫Then we have the double. 86 00:06:20,090 --> 00:06:24,350 ‫And the only difference is that here we have a 15 digit precision. 87 00:06:24,350 --> 00:06:28,820 ‫So if you need a higher precision and a higher range, then you would use double. 88 00:06:28,820 --> 00:06:32,270 ‫And as you can see, there is no F here and no D at the end. 89 00:06:32,270 --> 00:06:36,050 ‫This pretty much means that we are using a double here. 90 00:06:36,050 --> 00:06:39,800 ‫On the right hand side we have a double and on the left hand side we declare a double. 91 00:06:39,800 --> 00:06:41,300 ‫So this code works. 92 00:06:41,300 --> 00:06:47,840 ‫If you add an F here now, then you will have the same problem as if you had left out the F when creating 93 00:06:47,840 --> 00:06:48,680 ‫a float. 94 00:06:48,680 --> 00:06:51,080 ‫So you have to be precise here. 95 00:06:51,080 --> 00:06:57,590 ‫If you need even more precision and 28 digit precision, then you would use decimals. 96 00:06:57,590 --> 00:07:05,360 ‫So the data type decimal again in primitive data type, but a lot more precise when to use flow double 97 00:07:05,360 --> 00:07:05,990 ‫or decimal. 98 00:07:05,990 --> 00:07:07,550 ‫Well, the same story. 99 00:07:07,550 --> 00:07:12,620 ‫The smaller the value is, the smaller the data type should be. 100 00:07:12,620 --> 00:07:15,230 ‫So it has also to do with performance. 101 00:07:15,230 --> 00:07:22,490 ‫So if you want to create graphic libraries or if you want to write something that has high demands for 102 00:07:22,490 --> 00:07:27,050 ‫processing power, for example, in video games, then you would use float. 103 00:07:27,050 --> 00:07:34,500 ‫This is also used for physics in video games, so then Float is good enough in most real world examples. 104 00:07:34,500 --> 00:07:39,470 ‫Then you would use double except for money calculations and that's where you would use decimal. 105 00:07:39,470 --> 00:07:44,240 ‫So it's mostly used in financial applications where you need the highest level of accuracy. 106 00:07:45,050 --> 00:07:51,920 ‫Now there are other data types as well, primitive ones, and there is this boolean which is similar 107 00:07:51,920 --> 00:07:54,200 ‫to a switch which can only have two values. 108 00:07:54,200 --> 00:07:56,180 ‫So it can either be true or it can be false. 109 00:07:56,180 --> 00:07:57,050 ‫Nothing else. 110 00:07:57,060 --> 00:07:57,980 ‫Only those two. 111 00:07:58,920 --> 00:08:05,040 ‫Then we have the chart or character data type and it will only contain one single letter. 112 00:08:05,040 --> 00:08:09,690 ‫And in order to assign something, you need to use single quotations here. 113 00:08:09,690 --> 00:08:15,540 ‫So single quote start single quote ends and allows a single character literal or unicode. 114 00:08:15,540 --> 00:08:18,780 ‫So here you can store any type of Unicode in here. 115 00:08:18,990 --> 00:08:24,270 ‫And then if you need a longer text consisting of multiple different characters, then you would use 116 00:08:24,270 --> 00:08:24,810 ‫a string. 117 00:08:24,810 --> 00:08:27,120 ‫And you can see here we are using the double code. 118 00:08:27,120 --> 00:08:32,910 ‫So this is pretty much used for text and allows multiple letters and unicode in here. 119 00:08:33,590 --> 00:08:36,890 ‫Now let's start coding and dive right into it. 120 00:08:36,920 --> 00:08:39,440 ‫Oh, and don't forget to rate this course, please.