为了账号安全,请及时绑定邮箱和手机立即绑定

将参数传递给模板化类型的C#generic new()

将参数传递给模板化类型的C#generic new()

陪伴而非守候 2019-07-29 10:14:29
将参数传递给模板化类型的C#generic new()我正在尝试在添加到列表时通过其构造函数创建类型为T的新对象。我收到编译错误:错误消息是:'T':创建变量实例时无法提供参数但我的类确实有一个构造函数参数!我怎样才能做到这一点?public static string GetAllItems<T>(...) where T : new(){    ...    List<T> tabListItems = new List<T>();    foreach (ListItem listItem in listCollection)     {        tabListItems.Add(new T(listItem)); // error here.    }     ...}
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 571 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信