Here's som simple code to transform an array or list from one type to another:
// 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
[powered by WordPress.]
jour·nal n. A personal record of occurrences, experiences, and reflections kept on a regular basis; a diary.
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||
40 queries. 0.528 seconds
November 14th, 2009 at 17:41
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.