如果您有以下内容:
Public Class Person
{
public int Id;
Public String Name;
}
在Program.cs中,
String[] employeeList = new String[]{ 3, 5, 7 }
如何将employeeList转换为Person列表。我觉得它看起来像是:
List<Person> persons = employeeList
.Select( e=> new {
Id = e.ToString(),
Name = e.ToString() + "hello"
} );
答案 0 :(得分:3)
List<Person> persons = employeeList
// In the select part you just indicate the desired type to return
.Select(e => new Person {
Id = e.ToString(),
Name = e.ToString() + "hello"
}).ToList(); // and cast the resulted enumerable to List<Person>