相关疑难解决方法(0)

C#generic"where constraint"和"any generic type"定义?

让我举个例子:

  1. 我有一些通用的类/接口定义:

    interface IGenericCar< T > {...}

  2. 我有另一个类/接口,我想与上面的类相关,例如:

    interface IGarrage< TCar > : where TCar: IGenericCar< (**any type here**) > {...}

基本上,我希望我的通用IGarrage依赖于IGenericCar,无论是否,IGenericCar<int>或者IGenericCar<System.Color>因为我对该类型没有任何依赖性.

c# generics where type-constraints

107
推荐指数
2
解决办法
3万
查看次数

标签 统计

c# ×1

generics ×1

type-constraints ×1

where ×1