是否这些2个扩展方法是相同的或者是有一些危险中使用的2通用扩展方法:接口
public static T GetSomthingFromListOf<T>(this List<T> list)where T: IMyInterface
{
//do somthing that returns an item of T
}
对战
public static IMyInterface GetSomthingFromList(this List<IMyInterface> list)
{
//do somthing that returns an item of IMyInterface
}
很好解释,没有想到在第二个实现中我只能使用接口成员的事实。而在第一个示例中,我可以使用所有成员,只需要是IMyInterface类型。 所以我需要在我的问题第一个:)。 –
@Clint:如果'T'是一个结构? – apocalypse
@apocalypse我从来不需要一个接口的结构,但如果它是一个结构可能是什么问题? –