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

  • SEARCH
  • Home
  • 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 8230669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:12:42+00:00 2026-06-07T17:12:42+00:00

I have an object AppDetail containing 2 string properties, a name, and a version

  • 0

I have an object AppDetail containing 2 string properties, a name, and a version string (e.g. “1.0.0”)

Given a List< AppDetail > that contains duplicates of the same name but different version strings, how do I create a List with unique names, and highest versions?

e.g. from these 2 items in the initial list

"name", "1.0.1"
"name", "1.1.0"

I want the unique items list to contain only the second item, since it has the highest version.

To compare versions I need to create an IComparer that creates Version objects and then to use the version.CompareTo(version) method. But thats not useful, since the List.Distinct overload only accepts IEqualityComparer, not IComparer.

Any thoughts? Thanks

  • 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-06-07T17:12:44+00:00Added an answer on June 7, 2026 at 5:12 pm

    It makes sense that List.Distinct() doesn’t accept an IComparer, since determining if two items are distinct does not require knowing if one item would precede another (or visa versa,) which is the purpose of the IComparer interface. Rather, all that is needed is to know whether or not two items are equal, which is exactly why IEqualityComparer exists.

    You don’t need to implement either, though. You can create a query that selects the appropriate items, by first grouping all the items by name, and then selecting only the highest version number from each group:

    var namesWithHighestVersion = 
        appDetailList
            .GroupBy(x => x.Name)
            .Select(x => new AppDetail { 
                             Name = x.Key,
                             Version = x.Max(x => new Version(x.Version)).ToString()
                            })
            .ToList();
    

    Note that this creates a new list, rather than updating the old list.

    Also, you could simplify everything somewhat by making the original type use a Version, instead of a string.

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

Sidebar

Related Questions

I have an object Document with nested Properties (Name, Value) collection. Now I want
Lets say I have object Tom which has class Person. Class Person String Name
Can I have object with the same name as class in javascript?
Application use NHibernate. I Have object A that contains set of objects B. I
I have object A which contains multiple instances of object B, which in turn
I have two tables: object that has object_id column and avalues that have object_id
I think I read somewhere that some modules only have object oriented interfaces (
I have an object that cannot be copied, a NetGame because it has a
I have an object that has pairs of replacement values used for simple encoding
We have Object and ValueType .... And String .... String is derived from object,

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.