您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

具有“任何泛型类型”定义的C#泛型“ where约束”?

具有“任何泛型类型”定义的C#泛型“ where约束”?

通常有两种方法可以实现此目的。

添加一个参数来IGarrage表示T应该传递给IGenericCar<T>约束的参数:

interface IGarrage<TCar,TOther> where TCar : IGenericCar<TOther> { ... }

:定义一个基本接口,IGenericCar<T>该接口不是通用接口,并且针对该接口进行约束

interface IGenericCar { ... }
interface IGenericCar<T> : IGenericCar { ... }
interface IGarrage<TCar> where TCar : IGenericCar { ... }
c# 2022/1/1 18:19:32 有476人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶