Welcome back.
In this video we're going to look at another data type called int.
And int allows us to store numbers whole numbers because int stands for integer and integers are whole
numbers.
Now let's look at an integer.
Let's create another variable.
And in order to create a variable you start with the data type.
So let me write it out.
Data type variable name equals and then initial value and semicolon.
So this is generally how you assign or create a variable inside of C sharp where you specify the data
type manually.
And there are other ways to do it but we're going to cover that later on.
So for now let's say I want to use this data type called int, which is the keyword for an integer.
So here I'm going to call this one my number.
And let's say I want it to be zero.
So I assign the value zero because zero plus anything is still anything.
So that's why we can use this as the baseline number as the starting number so to speak.
Now we get these curly brackets where it says okay so you created this variable but you actually never
used it.
Well all right let's go ahead and use it.
Therefore I'm going to use a little trick I'm going to use a control write line statement.
But I'm going to save myself some time by just entering c w and then pressing tab twice.
And then you can see or actually once and you can see I get console dot write line here.
So here I can just say my number equals then plus my number.
Now this will give me my number.
So let me actually run this.
It will say enter something and then it will say my number.
There we are.
It says my number equals zero okay.
So we have this variable that we set up called my number.
And then we can reuse it at any later point inside of our program.
And that's the cool thing that we're doing here.
We did the same thing down here.
What we used this variable user input so that we could store something in there.
And then whenever we use the name of that variable somewhere else, it's basically as if we used whatever
is inside of it, whatever we put inside of it, we used that value for whatever purpose we want it
later on.
So for example, for addition, it would make sense to have both values and store them somewhere so
that we can add them together and build the sum.
So now if I go ahead and I actually use the user input like we did here and want to store a number,
I'm going to run into a little problem.
Let's try that.
So I'm going to say enter a number.
Actually let's let's put it up here.
Enter a number.
Then we enter the number using console read line.
And we're going to store that inside of our variable number.
And it's actually called my number.
So if we try to do that you see we get an error.
And let's hover over it to understand what the error is.
Because as a coder, fixing errors is one of the most important things that we do.
So it says here reads the text line of characters from the standard input stream, and then returns
next line of characters from the input stream or null if no more lines are available.
However, here the error that we're going to get or that we're getting here, it says cannot implicitly
convert type string to int.
So now we have a problem because on one hand we have one data type, and on the other hand we have another
data type.
And now we cannot fit them together.
We cannot like put them together unless we convert one of them.
So we're basically having a string and an int.
And we're trying to put whatever the string value is on that side actually for you, it's on that side.
We're trying to put that into a variable that only can contain ints.
Because my number we defined here is of type int.
So it can only contain whole numbers.
It cannot contain strings, cannot contain text.
Even though you could say a number is a text.
But from a data type perspective it isn't okay.
From a data type perspective, a number is a number and a string is a string.
Now there are different data types for numbers, but simplifying it.
This is what we're going to get here.
So how can we make sure that whatever we are entering is going to be stored as a number.
Therefore we can use something called parsing and parsing we're going to cover in the next video.