Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 33961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:00:13+00:00 2026-05-10T14:00:13+00:00

I have a List of Foo. Foo has a string property named Bar. I’d

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:00:13+00:00Added an answer on May 10, 2026 at 2:00 pm

    I’d go lambdas… wayyy nicer

    var bars = Foos.Select(f => f.Bar).Distinct().ToArray(); 

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of Foo . Foo has properties Bar and Lum .
I have a list of variable names, like this: ['foo', 'bar', 'baz'] (I originally
I have a List, it has Foo objects, and each Foo has a start
I imagine to use XML serialization like this: class Foo { public Foo (string
I have a list, list = ['foo','bar'] and now i want to create a
I have a List (Foo) and I want to see if it's equal to
I have a Foo object, and a std::list holding instances of it. My problem
Lets say I have an entity Foo, and it contains a list of another
I have a C# method which accepts a Predicate<Foo> and returns a list of
If I have List<String> text how can I create a sub-list of all continious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.