У меня есть код ниже:
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>' в 'System.Collections.Generic.List<string>'
'System.Collections.Generic.List<AnonymousType#1>'
'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():
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();
Если вы хотите, чтобы оно было List<string>, избавьтесь от анонимного типа и добавьте .ToList() вызов:
List<string>
.ToList()
List<string> list = (from char c in source select c.ToString()).ToList();
Если у вас есть источник в виде строки типа "abcd" и вы хотите создать список, подобный этому:
"abcd"
{ "a.a" }, { "b.b" }, { "c.c" }, { "d.d" }
, тогда вызовите:
List<string> list = source.Select(c => String.Concat(c, ".", c)).ToList();
попробуй
var lst= (from char c in source select c.ToString()).ToList();
Я думаю, что ответы ниже
List<string> aa = (from char c in source select c.ToString() ).ToList(); List<string> aa2 = (from char c1 in source from char c2 in source select string.Concat(c1, ".", c2)).ToList();