列表和集合的通用约束

Generic constrain for Lists and Collections

我有一个看起来像这样的通用方法:

public int GetCount<T>(T collection) where T: ICollection
{
   return collection.Count;    
}

现在我希望能够调用此方法,其中集合参数可以是 List<T>HashSet<T>。当前代码不满足该要求,因为我要传递的参数不继承 ICollection 接口。现在有什么方法可以通过简单的约束来实现吗?

为什么不:

public int GetCount<T>(ICollection<T> collection)
{
   return collection.Count;    
}