c# - get distinct item in List with highest value in property -


I have a string property, a name and a version string (such as "1.0.0") containing an object Aepditl < / P>

provided a list & lt; AppDetail & gt; In which there are duplicates of the same name but different version string, how do I create a list with the specific names and the highest version? , "1.0.1" "name", "1.1.0"

/ Pre>

I want the list of exclusive items to contain only the second item, because it has the highest version.

To compare versions I need to create an ICMP which creates the version object and then to use the version. The compatrate (version) method but this is not useful, because only the iQaal compactor accepts, not the ICMPrier.

Any thoughts? Thank you

It makes sense List.Distinct () accept After knowing that IComparer , after determining that the IComparer interface, instead of knowing that two items equals Whether or not the IEqualityComparer exists

You do not need it either to apply, though. You can create a query that selects the appropriate item, first grouped by all the names, and then only selecting the highest version number from each group:

  Various names are with the names = appDetailList .GroupBy (x = & Gt; x.Name). Select (x = & gt; New App Dabble {name = x, version = x.max (x = & gt; new version (x version)) ToString ()}) .Ollist ();   

Note that this creates a new list instead of updating the old list.

In addition, you can replace the original type with a version , instead of a string.

Comments