我在编写使用泛型的类时遇到了一些麻烦,因为这是我第一次创建一个使用泛型的类。C#泛型需要帮助
我想要做的就是创建一个方法,将List转换为EntityCollection。
我正在编译器错误: 类型“T”必须是引用类型,以便在通用类型或方法使用它作为参数“TEntity”“System.Data.Objects.DataClasses.EntityCollection”
这里是我想使用的代码:
public static EntityCollection<T> Convert(List<T> listToConvert)
{
EntityCollection<T> collection = new EntityCollection<T>();
// Want to loop through list and add items to entity
// collection here.
return collection;
}
据抱怨的代码的EntityCollection收集=新EntityCollection()线。
如果有人可以帮我解决这个错误,或向我解释为什么我收到它,我将不胜感激。谢谢。
我发现这个答案有编译最低要求。 – Andez 2015-02-04 21:49:05