我有这个类:这是什么意思:类名<T>其中T:
public static class Repository<T> where T : class
{
....
}
我明白public
和static
和class
和Repository<T>
,但我不理解这一点:
where T : class
是否Repository
延伸或实施class
?或者: class
参考<T>
类型?
!! ALSO !!:
而且,如果我有一个抽象基类DataAccessBase
,我想这个类Repository
继承,我该怎么办呢?
它是[类型约束](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters)。 –
'where T'指'T'类型后的声明。另外,你将它实例化为任何其他泛型类,':class'将类型限制为引用类型,而不是值类型。 – Gusman
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/where-generic-type-constraint –