如何使用TModel创建ICollection?

时间:2014-01-05 11:15:00

标签: c# parameter-passing icollection

所以我有一个名为Repository的类,它拥有这个方法:

public IEnumerable<TModel> UpdateOrCreate<TModel>(ICollection<TModel> itemsToUpdate)
        where TModel : EndpointModelBase
{
    //Do Stuff
}

如何使用正确的参数调用此方法? 我的麻烦来自于尝试为要传入的参数设置ICollection?

1 个答案:

答案 0 :(得分:3)

您可以传递List<EndpointModelBase>,因为它实现了ICollection<T>

List<EndpointModelBase> itemsToUpdate = new List<EndpointModelBase>();
UpdateOrCreate<EndpointModelBase>(itemsToUpdate);