草庐IT

DoSomethingWithTheSameTypeAsMe

全部标签

c# - 这个参数类型约束是什么意思?

我正在查看一些代码,但我不明白以下类定义中特定约束的含义:internalabstractclassEntity:EntitywhereT:Entity{...}我不明白这对参数类型T意味着什么。 最佳答案 这类似于“CuriouslyRecurringTemplatePattern”(但不相同)。它可以(除其他外)用于帮助将派生类中方法的参数类型限制为与派生类本身相同的类型。Here'saninterestingblogpostfromEricLippertonthissubject.这个的主要用途是强制派生自Entity的类实现

c# - 这个参数类型约束是什么意思?

我正在查看一些代码,但我不明白以下类定义中特定约束的含义:internalabstractclassEntity:EntitywhereT:Entity{...}我不明白这对参数类型T意味着什么。 最佳答案 这类似于“CuriouslyRecurringTemplatePattern”(但不相同)。它可以(除其他外)用于帮助将派生类中方法的参数类型限制为与派生类本身相同的类型。Here'saninterestingblogpostfromEricLippertonthissubject.这个的主要用途是强制派生自Entity的类实现