草庐IT

IGenericCar

全部标签

具有 "where constraint"定义的 C# 泛型 "any generic type"?

举个例子:我有一些通用的类/接口(interface)定义:interfaceIGenericCar{...}我有另一个类/接口(interface)想与上面的类关联,例如:interfaceIGarrage:whereTCar:IGenericCar{...}基本上,我希望我的通用IGarrage依赖于IGenericCar,不管它是IGenericCar或IGenericCar,因为我对该类型没有任何依赖性。 最佳答案 通常有两种方法可以实现这一点。选项1:向IGarrage添加另一个参数代表T应该传递给IGenericCar约

具有 "where constraint"定义的 C# 泛型 "any generic type"?

举个例子:我有一些通用的类/接口(interface)定义:interfaceIGenericCar{...}我有另一个类/接口(interface)想与上面的类关联,例如:interfaceIGarrage:whereTCar:IGenericCar{...}基本上,我希望我的通用IGarrage依赖于IGenericCar,不管它是IGenericCar或IGenericCar,因为我对该类型没有任何依赖性。 最佳答案 通常有两种方法可以实现这一点。选项1:向IGarrage添加另一个参数代表T应该传递给IGenericCar约