How does generic type inference work in C#?
问题 If I have the following code private BaseMessage getMessage() { return new OtherMessage(); } private void CheckType<T>(T type) { Console.WriteLine(type.GetType().ToString()); Console.WriteLine(typeof(T).ToString()); } private void DoChecks() { BaseMessage mess = getMessage(); CheckType(mess); } why do I get different types outputted? Is there anyway of getting the type inference to use the actual type of the object being passed? 回答1: Generic type inference means that the compiler