我有下面的代码:
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<AnonymousType#1>'
to 'System.Collections.Generic.List<string>'
需要帮忙。
IEnumerable<string> e = (from char c in source
select new { Data = c.ToString() }).Select(t = > t.Data);
// or
IEnumerable<string> e = from char c in source
select c.ToString();
// or
IEnumerable<string> e = source.Select(c = > c.ToString());
然后你可以打电话ToList()
:
List<string> l = (from char c in source
select new { Data = c.ToString() }).Select(t = > t.Data).ToList();
// or
List<string> l = (from char c in source
select c.ToString()).ToList();
// or
List<string> l = source.Select(c = > c.ToString()).ToList();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)