[英]How to cast into a list from a Linq lambda expression
如果您具有以下條件:
Public Class Person
{
public int Id;
Public String Name;
}
在Program.cs中,
String[] employeeList = new String[]{ 3, 5, 7 }
您如何將employeeList轉換為人員列表。 我以為它看起來像:
List<Person> persons = employeeList
.Select( e=> new {
Id = e.ToString(),
Name = e.ToString() + "hello"
} );
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.