Search code examples
c#linqilist

query ilist with linq


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?


Solution

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

    emailList will now contain only the email addresses.