How can you find out what is the variable type?

Experience Level: Junior
Tags: C#

Answer

One quick way how to find out what is the data type of a variable is to put the mouse cursor over it in Visual Studio. The tooltip will appear and the variable data type will be displayed in the tooltip.

Another way is to find the declaration of the variable. Go from the line in the source code you are looking at and continue to the top until you see the variable declaration.

The you will see the data type specified on the left hand side from the variable name. Or you will see 'var' keyword on the left hand side and then you need to look at the right hand side from the assignment operator and figure out what is the data type of the right hand side expression. If it's a constant value, then the data type of your variable is the same as the data type of the constant. If it's a method, your variable data type will be the same as the method return value data type. If it's a property, your variable data type will be the same as he property data type.

Related C# job interview questions
C# for beginners
C# for beginners

Are you learning C#? Try our test we designed to help you progress faster.

Test yourself