C#中的LINQ - 无法隐式转换IEnumerable的<串GT;列出<串GT; [英] C# Linq - Cannot implicitly convert IEnumerable<string> to List<string>

查看:114
本文介绍了C#中的LINQ - 无法隐式转换IEnumerable的<串GT;列出<串GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样定义的列表:

public List<string> AttachmentURLS;



我将项目添加到列表如下:

I am adding items to the list like this:

instruction.AttachmentURLS = curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment => !String.IsNullOrEmpty(Attachment));



但我收到此错误:无法隐式转换IEnumerable的到列表

But I am getting this error: Cannot implicitly convert IEnumerable to List

我在做什么错了?

推荐答案

Where方法返回一个的IEnumerable< ; T> 。尝试添加

The Where method returns an IEnumerable<T>. Try adding

.ToList()

要像这样结束:

instruction.AttachmentURLS = curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment => !String.IsNullOrEmpty(Attachment)).ToList();

这篇关于C#中的LINQ - 无法隐式转换IEnumerable的&LT;串GT;列出&LT;串GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆