How to know the data type of value entered by user at runtime in textbox?
问题 How to know the data type of value entered by user at runtime in textbox? My simple example: I've tried it by using GetType() , but it was useless, it always shows System.String , whether I enter int or String . 回答1: If the user has typed text into a textbox, that's always a string. It's never an int. You can parse the text as an integer, but the input itself is still text. You could speculatively try to parse it in different ways: int intValue; if (int.TryParse(text, out intValue) { ... use