Welcome back.
In this video we're going to talk about implicitly typed variables.
So there are explicitly typed variables.
So this one here is an explicitly typed variable.
And then there are implicitly typed variables.
Implicitly typed variables.
And how do you do that is by using the var keyword.
So you can use the var keyword and then the variable name.
So here for example my favorite genre and let's say it's lit RPGs.
So I've recently found out that there's this concept of lit RPGs in audio books.
And I love it.
So here you see I did not say that this is a string.
But you see, it says that it is a string once you hover over it.
So how does this variable know that it has to be of type string?
Well, it's because it implicates it based on the data type that I assigned to it.
So here I am assigning a string to this variable called my favorite genre.
So if I had a variable called my favorite number and let's say it was 13.
Now this is not a string but it's an int 32.
So by default it has assigned the data type int to my favorite number.
So now once I use it later on it will know that my favorite number is in fact an int.
So if I now go ahead and say your favorite number as well.
Favorite number.
And let's say it's 14 and I create an int our numbers combined.
And I just say my favorite number plus your favorite number.
That will work because both of those are ints.
But let's say this weren't an INT but it were a string that would not work because we cannot assign
an int into a string.
Okay, so that's something you have to consider whenever you're working with var.
So with implicitly typed variables, this one could also be an implicitly typed variable.
And it would understand that on the right hand side.
So on the right side I think like this for you of the equation sign there are integers.
So I'm going to hold integers which means my type is going to be integer or int.
So this will be the int type here as well because it implicitly found out that it has to hold ints.
So from now on it can only hold ints.
I cannot go ahead and go ahead and say here our numbers combined and suddenly say my or like 25 or something
like that.
That doesn't work okay, because now this will forever be an int, it will only be able to hold ints.
So that's implicitly typed variables.
So if you ever see this var keyword you know what it is and how to treat it.