使用LINQ隐式转换List <t>到CustomList <t>的错误?

时间:2015-05-04 18:44:25

标签: c# linq generics

如何将List转换为List<T>

 var memberCommunicationPreferenceses = new PersonifyCollection<MemberCommunicationPreferences>();

memberCommunicationPreferenceses = (from ICustomerOptIn customerOptIn in customerData.CustomerOptIns
        select new Models.MemberCommunicationPreferences()
       {
         MemberCommunicationsPrefernceId = customerOptIn.CustomerOptInId.ToString(CultureInfo.InvariantCulture),
         ShortName = customerOptIn.OptionShortNameString,
         ShortNameDescription = customerOptIn.OptionShortName.Description
         .....
       }).Where(x=>x.OptedInFlag).ToList();

错误

Error   23  Cannot implicitly convert type 'System.Collections.Generic.List<EBusiness.Model.Models.MemberCommunicationPreferences>' 
 to 'EBusiness.Model.Models.Collections.PersonifyCollection<.EBusiness.Model.
  Models.MemberCommunicationPreferences>'   C:\\Trunk\Source\EBusiness\EBusiness.Model\Concrete\Personify\
     PersonifyMemberCommunicationPreferences.cs 94  31  EBusiness.Model

更新

-

根据本文enter link description here

中的第二个答案的PersonifyCollection代码

1 个答案:

答案 0 :(得分:0)

我们不知道您的PersonifyCollection课程有哪些方法,因此我们无法告诉您如何转换为该方法,或者是否有任何方法可以这样做。你可以尝试:

var something=new PersonifyCollection<MemberCommunicationPreferences>(memberCommunicationPreferences);

如果你的自定义集合实现了采用IEnumerable的标准构造函数,那么它应该可以工作。