I’m in the immediate window in Visual Studio. There’s a variable p. How can I deduce the type of the variable p?
I tried p.GetType() but that returns the type of object p. In my case, this is a very specific type (eg. sometimes ChessPlayer, sometimes TennisPlayer). I’d like to know the type of the variable, ie. the type that determines what methods are available on the variable p.
Edit: I think this is a reasonable thing to want to do. I am trying to inspect the variable p but I don’t know it is! Normally in Visual Studio I just hover the mouse on the variable and it tells me its type, or I type . and the autocomplete lists its methods. However none of that works in the immediate window, all I have is this variable p I don’t know what it is or what I can do with it 🙁
Surprised this was so difficult, in the end I wrote this method, which seems to give the right answer.
Example usage:
Prints
System.Collections.IList