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 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

Ask A Question

Stats

  • Questions 253k
  • Answers 253k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended up creating a custom SiteMapProvider. May 13, 2026 at 9:57 am
  • Editorial Team
    Editorial Team added an answer I mean, there's this: Func<Thing> f = () => new… May 13, 2026 at 9:57 am
  • Editorial Team
    Editorial Team added an answer My database connection generally resides in a wrapper, so there's… May 13, 2026 at 9:57 am

Related Questions

I have a situation where I'm lazy loading images from the www. It's a
I am trying to perform what I can only describe as the reverse version
(Title and contents updated after reading Alex's answer) In general I believe that it's
First of all, some links to pages I've used for reference: A SO question
Sorry for what is a generic title. I'm not the best at titles. Anyway

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.