【发布时间】:2009-02-05 11:05:19
【问题描述】:
下面的代码段打印出“类型不一样。”。为什么?我知道使用interfaceOnMyType.GetGenericTypeDefinition() 可以解决问题,但我为什么要这样做?
class Program
{
static void Main(string[] args)
{
var myType = typeof(Baz<>);
var interfaceOnMyType = myType.GetInterfaces().SingleOrDefault();
var exactType = typeof(IBar<>);
if (exactType == interfaceOnMyType)
{
Console.WriteLine("The types ARE the same.");
}
else
{
Console.WriteLine("The types ARE NOT the same.");
}
Console.ReadLine();
}
}
interface IBar<T>
{
}
class Baz<T> : IBar<T>
{
}
【问题讨论】: