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 556427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:55:06+00:00 2026-05-13T11:55:06+00:00

If have a class of Widgets like this: public class Widget { public double

  • 0

If have a class of Widgets like this:

public class Widget
{
   public double Price { get; set; }
   public string Type { get; set; }
   public int ID { get; set; }
   public string Name { get; set; }
}

And create a list of them:

List<Widget> Widgets = new List<Widget>
   {
       new Widget {ID = 1, Name = "One", Price = 3.00, Type = "Gooy"},
       new Widget {ID = 2, Name = "Two", Price = 5.00, Type = "Crispy"},
       new Widget {ID = 2, Name = "Three", Price = 3.00, Type = "Hard"},
       new Widget {ID = 2, Name = "Four", Price = 3.00, Type = "Chewy"},
       new Widget {ID = 2, Name = "Five", Price = 2.50, Type = "Gooy"}
   };

And then I call IEnumerable.Distinct with a custom comparer like so:

IEqualityComparer<Widget> widgetComparer = 
   new LambdaComparer<Widget>((item1, item2) => item1.Price == item2.Price);

Widgets.Distinct(widgetComparer);

Then (as I see it) there should be 3 objects returned (one for each price category).

What is the Type of the 3.00 one (Gooy, Hard or Chewy)?

Does it pick one? (I am trying to understand distinct better because my real distinct is not giving me distinct results.)

  • 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. Editorial Team
    Editorial Team
    2026-05-13T11:55:07+00:00Added an answer on May 13, 2026 at 11:55 am

    Distinct takes whatever the comparer determines; so if there are 3 different objects with the same price, and your custom comparer only looks at the price, then it should consider them one and the same, depending on how the comparison takes place.

    HTH.

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

Sidebar

Related Questions

No related questions found

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.