© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
10 replies
mr.rendero

✅ LINQ get items with priority

Hello, can I get some assistance with the following issue:

public class Item
{
  public string Name { get; set; }
  public string Identifier { get; set; }
}
public class Item
{
  public string Name { get; set; }
  public string Identifier { get; set; }
}


So I have a collection of items (List<Item>) and I need some sort of filtering on them.
Lets say we have the following items in the collection:

Item 1:
Name - Retail
Identifier - 001

Item 2:
Name - Retail
Identifier - 111

Item 3:
Name - Hospital
Identifier - 111

Item 4:
Name - Hospital
Identifier - 002

As you can see "Item 2" and "Item 3" have the same Identifier.
In those cases where "Identifier" is equal for 2 or more items, I need to take only the one with priority which in my case is "Retail".
The final collection that I need to get after filtering is the following:

Item 1:
Name - Retail
Identifier - 001

Item 2:
Name - Retail
Identifier - 111

Item 3:
Name - Hospital
Identifier - 002

I'm not sure how to do that with LINQ. Any help will be appreciated, thank you 🙂
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Help with Linq
C#CC# / help
4y ago
Get max index using linq
C#CC# / help
3y ago
❔ XMLAttributeCollection -> Dictionary with LINQ?
C#CC# / help
3y ago