How can you declare a variable?
Experience Level: Junior
Before you can use a variable you have to declare it first. The variable can be declared either implicitly using the 'var' keyword or explicitly specifying a data type the variable should have.
In the code below: The variable x is declared implicitly. Its data type wasn't explicitly specified, instead, in the place of the data type the keyword 'var' is used. Because the data type isn't explicitly specified and every variable needs to have its data type, the data type gets inferred from the value that is assigned to the variable.
The variable y is declared explicitly, which means its data type was specified before any value got assigned to the variable.
Related C# job interview questions
What is a static method in C#?C# Junior
How can you find out what is the variable type?C# Junior
How can you assign a value to a variable in C#?C# Junior
What is a 'var' keyword in C# good for?C# Junior
What is a variable?C# Junior