Here’s som simple code to transform an array or list from one type to another:
Kursdeltagare[] kdArr = ... // Alternative 1 var kdDtos = matchingKd.Select(kd => new KursdeltagareDto() { PersonId = kd.PersonID, Fornamn = kd.Fornamn, Efternamn = kd.Efternamn }).ToList(); // Alternative 2 var kdDtos2 = (from kd in matchingKd select new KursdeltagareDto() { PersonId = kd.PersonID, Fornamn = kd.Fornamn, Efternamn = kd.Efternamn } ).ToList();
Both alternatives will give the same result but the first one contains slightly less code. Which is better from a performance point of view? If you know, feel free to leave a comment…
/Emil
I believe those are exactly the same. Linq queries are converted to calls to lambda extension methods by the compiler. I guess that if you looked at the IL code generated by both alternatives, it would probably be exactly the same.