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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:28:03+00:00 2026-05-13T06:28:03+00:00

I have a list of items. Item is a object with two fields. One

  • 0

I have a list of items. Item is a object with two fields. One field is of type Dictionary<string, List<string> and second filed is of type int.
Now I want to check if there is an item with both fields unique in that list.
With dict field I care about key part, not value so value part may be the same between items.
It is key that must be unique in that list.

If such element exists I want to be able to get position of that element in my list.

Hope it is clear.

To clarify –

Here is my class

namespace Polstyr
{
class RecordItem
{
    Dictionary<string, List<string>> dict;

    public string MachineNr { get; set; }

    public RecordItem()
    {
        dict = new Dictionary<string, List<string>>();
    }

    public void AddToDict(string value, List<string> list)
    {
        dict.Add(value, list);
    }

    public Dictionary<string, List<string>> GetDictionary
    {
        get
        {
            return dict;
        }
    }
}

}

In other part of my code I have list of type List<RecordItem> named recordItems.

I would like to check there is RecordItem object in recordItems list that is unique in that
list based on it’s fields. Key in dict must be unique and MachineNr must be unique.

Thanks in advance.

  • 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-13T06:28:04+00:00Added an answer on May 13, 2026 at 6:28 am

    Here’s a LINQ solution which I believe will work.

    Given:

    class A
    {
        // your int field
        public int Bar{get; set;} 
    
        // your dictionary (the value is irrelevant so I've just used bool)
        public Dictionary<string, bool> Foo{ get; set; } 
    }
    

    Then:

    var nonUniqueFoo = list.SelectMany(a => a.Foo.Keys)
                        .GroupBy( s => s)
                        .Where( g => g.Count() > 1)
                        .Select(g => g.Key);
    
    
    var nonUniqueBar = list.Select(a => a.Bar)
                        .GroupBy( i => i)
                        .Where( g => g.Count() > 1)
                        .Select(g => g.Key);
    
    var uniqueObjects = list.Where( a=> !nonUniqueBar.Contains(a.Bar) )
                           .Where( a => !nonUniqueFoo.Intersect(a.Foo.Keys).Any() )
                  ;
    

    For completeness, here’s my test data:

    List<A> list = new List<A>();
    list.Add( new A{ Bar=1, Foo = new Dictionary<string, bool>{ {"123", true} } } );
    list.Add( new A{ Bar=2, Foo = new Dictionary<string, bool>{ {"456", true}, {"789", true}, {"567", true} } } );
    list.Add( new A{ Bar=3, Foo = new Dictionary<string, bool>{ {"AAA", true}, {"456", true}, {"567", true} } } );
    
    • 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 objects, each object with two fields of interest which
I have a list of items: <item>a</item> <item>x</item> <item>c</item> <item>z</item> and I want as
I have a simple unordered list with list items as menu item i created
I have a list of items, where each item is a simple class containing
I have a list of items. When I create the list each item has
I have a list of items, like a menu, where the current item has
Say I have a list of items from a database. Next to each item
I have here a list of items in a table. Each item has a
I have the following code: SPList list = web.Lists[this.ListName]; SPListItem item = list.Items.Add(); now
I have a list view that displays a collection of items, each item has

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.