How to get compile time type of a variable?
问题 I'm looking for how to get compile time type of a variable for debugging purposes. The testing environment can be reproduced as simply as: object x = "this is actually a string"; Console.WriteLine(x.GetType()); Which will output System.String . How could I get the compile time type System.Object here? I took a look over at System.Reflection , but got lost in the amount of possibilities it provides. 回答1: I don't know if there is a built in way to do it but the following generic method would do