GetType() and Typeof() in C#
问题 itemVal = "0"; res = int.TryParse(itemVal, out num); if ((res == true) && (num.GetType() == typeof(byte))) return true; else return false; // goes here when I debugging. Why num.GetType() == typeof(byte) does not return true ? 回答1: Because num is an int , not a byte . GetType() gets the System.Type of the object at runtime. In this case, it's the same as typeof(int) , since num is an int . typeof() gets the System.Type object of a type at compile-time. Your comment indicates you're trying to