在List<>之间复制一些值和List2<>

时间:2012-05-04 00:15:06

标签: c# asp.net list ienumerable

我有2个LIST

List<PrimeraVueltaFindResult> ListaPrimeraVuelta = new List<PrimeraVueltaFindResult>();
List<RutaCriticaFindResult> result = new List<RutaCriticaFindResult>();

public class PrimeraVueltaFindResult
{
    [DataMember]
    public string Descripcion { get; set; }

    [DataMember]
    public string JobNameInicio { get; set; }

    [DataMember]
    public string GroupInicio { get; set; }

    [DataMember]
    public string StartRun { get; set; }

    [DataMember]
    public string JobNameFin { get; set; }

    [DataMember]
    public string GroupFin { get; set; }

    [DataMember]
    public string EndRun { get; set; }
}

public class RutaCriticaFindResult
{
    [DataMember]
    public int RutaCriticaId { get; set; }

    [DataMember]
    public string StartRun { get; set; }

    [DataMember]
    public string EndRun { get; set; }

}

我需要在PrimeraVueltaFindResult列表值中复制StartRun和EndRun。

请问我该怎么办?

1 个答案:

答案 0 :(得分:4)

要将ListaPrimeraVuelta中的所有数据复制到新的RutaCriticaFindResult对象中,您可以使用LINQ:

var rutaCriticaFindResults = ListaPrimeraVuelta.Select(result => 
    new RutaCriticaFindResult 
    { 
        StartRun = result.StartRun, 
        EndRun = result.EndRun 
    });

var result = rutaCriticaFindResults.ToList();