namespace Lesson5_泛型练习 { internal class Program { static void Main(string[] args) { Console.WriteLine("Hello, World!"); Console.WriteLine(InputType()); Console.WriteLine(InputType()); Console.WriteLine(InputType()); Console.WriteLine(InputType()); Console.WriteLine(InputType()); } public static string InputType() { if (typeof(T) == typeof(int)) { return string.Format("{0},{1}字节", "整形", sizeof(int)); }else if (typeof(T) == typeof(float)) { return string.Format("{0},{1}字节", "单精度浮点数", sizeof(float)); }else if (typeof(T) == typeof(double)) { return string.Format("{0},{1}字节", "双精度浮点数", sizeof(double)); }else if (typeof(T) == typeof(string)) { return string.Format("{0},{1}字节", "字符串", "不定长"); } return "其他类型"; } } }