Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Map one type to another

I need to find difference between to sets. Classes ,comprising the sets, are different but have same type of fields. To be able to use Except method ,to take the difference, i want to map one list to another.

Can i do this using toList method? if not, Is it possible in another way?

List<Class1>.Except(List<Class2> I need to map class2 list to class1 list)

Thanks

like image 571
mehmet6parmak Avatar asked Dec 26 '10 14:12

mehmet6parmak


1 Answers

In LINQ, Select is synonymous with "map" in other languages. It is called "select" because the word comes from database terminology... but Select is what you want:

var mappedTypes = myCollection.Select(item => new MappedType(item.Something));

like image 82
Brian Genisio Avatar answered Sep 29 '22 10:09

Brian Genisio