无法隐式转换类型“System.Collections.Generic.IEnumerable”到“System.Collections.Generic.List<字符串>”字符串>
我有下面的代码:
List<string> aa = (from char c in source
select new { Data = c.ToString() }).ToList();
怎么办
List<string> aa = (from char c1 in source
from char c2 in source
select new { Data = string.Concat(c1, ".", c2)).ToList<string>();
但是编译时出现错误
无法将类型
'System.Collections.Generic.List
隐式转换为' 'System.Collections.Generic.List
'
需要帮助。
I have the code below:
List<string> aa = (from char c in source
select new { Data = c.ToString() }).ToList();
But what about
List<string> aa = (from char c1 in source
from char c2 in source
select new { Data = string.Concat(c1, ".", c2)).ToList<string>();
While compile getting error
Cannot implicitly convert type
'System.Collections.Generic.List<AnonymousType#1>'
to'System.Collections.Generic.List<string>'
Need help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
然后你可以调用
ToList()
:Then you can call
ToList()
:如果您希望它是
List
,请删除匿名类型并添加.ToList()
调用:If you want it to be
List<string>
, get rid of the anonymous type and add a.ToList()
call:尝试
try
如果您有像
"abcd"
这样的字符串源并且想要生成如下列表:然后调用:
If you have source as a string like
"abcd"
and want to produce a list like this:then call:
我认为答案如下
I think the answers are below