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.

Comments

No Comments Yet.
Be the first to tell us what you think.
C# for beginners
C# for beginners

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

Test yourself

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

Anonymous
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
Anonymous
e
Anonymous
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e