Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query ilist with linq

Tags:

c#

linq

ilist

I would like to get data with linq from ilist which has type of one class - for example - iList - everything I know, that in this iList are saved emails and names, but this iList has no string type, but this class. How can I get them? It would be great to put this data to my own List Any hint how to do that?

like image 644
Martin Ch Avatar asked Dec 10 '25 09:12

Martin Ch


2 Answers

IList<MyNameAndEmailClass> myList = GetMyList();
var emailList = myList.Select(x => x.EmailAddress).ToList();

emailList will now contain only the email addresses.

like image 174
dlev Avatar answered Dec 12 '25 21:12

dlev


Is this what you want?

var result = list.OfType<SomeType>()
like image 45
Stecya Avatar answered Dec 12 '25 22:12

Stecya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!