当前位置: 首页 > 编程语言 > C#

C#Linq-CannotimplicitlyconvertIEnumerabletoListShare

时间:2023-04-10 17:57:56 C#

C#Linq-CannotimplicitlyconvertIEnumerabletoList我有一个这样定义的列表:我正在添加到列表项,如下所示:instruction.AttachmentURLS=curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment=>!String.IsNullOrEmpty(Attachment));但我收到此错误:无法将IEnumerable隐式转换为列表我做错了什么?Where方法返回IEnumerable。尝试像这样添加.ToList():instruction.AttachmentURLS=curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment=>!String.IsNullOrEmpty(Attachment)).ToList();像这样将.ToList()移到指令末尾Where扩展方法返回IEnumerable,Where将在数组上工作,因此在Split之后不需要ToList。.ToList()应该是最后一个。因为在您的代码中,您首先执行.ToList()操作,然后再执行先前的状态。Where方法返回IEnumerable。以上就是C#学习教程:C#Linq-IEnumerable不能隐式转换为List分享全部内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注。本文来自网络收集,不代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: