I have a List of Foo.
Foo has a string property named Bar.
I’d like to use LINQ to get a string[] of distinct values for Foo.Bar in List of Foo.
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d go lambdas… wayyy nicer
works the same as what @lassevk posted.
I’d also add that you might want to keep from converting to an array until the last minute.
LINQ does some optimizations behind the scenes, queries stay in its query form until explicitly needed. So you might want to build everything you need into the query first so any possible optimization is applied altogether.
By evaluation I means asking for something that explicitly requires evalution like ‘Count()’ or ‘ToArray()’ etc.