13

Is there a way to see the type of a var within the Visual Studio 2013 code editor?

When I have a crazy linq query it would be nice to see what the resulting type will be. I don't want to replace the var keyword with the actual type, I just want to see what it is.

9 Answers9

18

There is also a keyboard shortcut that will show you. Put the cursor over var and type:

ctrl+k, i

enter image description here

Philip Pittle
  • 11,821
  • 8
  • 59
  • 123
10

For newer versions of VS (I'm not sure this applies to 2013), you have the option to go down to:

Tools > Options > Text Editor > C# > Advanced

Scroll down to the "Inline Hints' section and enable Display inline type hints to show type hints inline with the line where the var is specified. There's also an option to display parameter name hints there, also very useful.

Jasper
  • 1,697
  • 2
  • 23
  • 48
9

You can get it by Hovering on particular var keyword.

For example see in below image the tooltip shows the details.

enter image description here

Neel
  • 11,625
  • 3
  • 43
  • 61
  • Does anyone know how to get this to work while debugging? When debugging I can't hover over fields/methods to see their descriptions, but CTRL-K, I works when debugging. – Vapid May 12 '20 at 08:02
3

Hover your mouse over the var keyword, it will show it in a tooltip.

Dominique
  • 16,450
  • 15
  • 56
  • 112
Fordio
  • 3,410
  • 2
  • 14
  • 18
  • 2
    You can also use F12 to go to definition on the `var` keyword, and it'll take you to the class. – NibblyPig Oct 01 '14 at 08:52
  • Will it do this for the result of a `linq` query? –  Oct 01 '14 at 09:19
  • Yes, the compiler can still infer the type from a linq query - unless you select an anonymous type, I'm not sure what it does then. – Fordio Oct 01 '14 at 09:45
2

Hover on the variable... It will tell you.

Whoami
  • 334
  • 4
  • 16
2

The text of the type can often be obtained (using copy and paste) by temporarily changing the var to an explicit type, say int. That will force a compilation error. After doing a Build solution the type of the variable should be written in both the Error list and the Output panes.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
1

Move your mouse cursor hover the var keyword, a tooltip will show you the actual type.

ken2k
  • 48,145
  • 10
  • 116
  • 176
1

enter image description here For Vs 2019 or 2022 Go to visual studio Option > Text Editor > c# > Advanced > Display inline type hints

enter image description here

arman
  • 649
  • 1
  • 10
  • 27
0

Add a variable watch. Check the type in the watch window.

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206