有两个类:
public class Persons
{
public int Id { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public int Phone { get; set; }
public DateTime Time { get; set; }
}
public class Phones
{
public string Name { get; set; }
public int Phone { get; set; }
}
我需要使用linq为PhoneList获取Persons的投影:
List<Persons> personList = List<Persons>{...};
List<PhoneList> phoneList = persons...
我怎么得到它?
答案 0 :(得分:0)
使用Select
子句进行投影:
List<PhoneList> phoneList = personList.Select(x => new Phones { Name = x.Name, Phone = x.Phone }).ToList();