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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:42:50+00:00 2026-05-26T15:42:50+00:00

I have this dictionary mappings declared as a Dictionary<string, HashSet<string>> . I also have

  • 0

I have this dictionary mappings declared as a Dictionary<string, HashSet<string>>.
I also have this method to do stuff on a hashset in the dictionary:

public void DoStuff(string key, int iClassId){
    foreach (var classEntry in
             from c in mappings[key]
             where c.StartsWith(iClassId + "(")
             select c)
    {
        DoStuffWithEntry(classEntry);
    }
}

private void DoStuffWithEntry(string classEntry){
    // Do stuff with classEntry here
}

In one case, I need to do this on a number of keys in the mappings dictionary, and I was thinking it was better to rewrite and filter on a list of keys instead of calling DoStuff for each key to optimise the execution.

Currently I do this:

DoStuff("key1", 123);
DoStuff("key2", 123);
DoStuff("key4", 123);
DoStuff("key7", 123);
DoStuff("key11", 123);

Logically something like this instead of calling DoStuff for each (FilterOnKeys is not a method – just what I want…):

    foreach (var classEntry in
             from c in mappings.FilterOnKeys("key1", "key2", "key4", "key7", "key11")
             where c.StartsWith(iClassId + "(")
             select c)
    {
        DoStuffWithEntry(classEntry);
    }
  • 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-26T15:42:51+00:00Added an answer on May 26, 2026 at 3:42 pm

    It sounds like you want:

    string[] keys = { "key1", "key2", ... }
    var query = from key in keys
                from c in mappings[key]
                ...;
    
    foreach (var entry in query)
    {
        ...
    }
    

    (I would personally use a separate variable for the query just for readability – I’m not too keen on the declaration bit of a foreach loop getting huge.)

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

Sidebar

Related Questions

I have a ComponentResourceKey defined in my resource dictionary like this: <Style x:Key={ComponentResourceKey TypeInTargetAssembly={x:Type
I have a Dictionary called AvailableBoxes. I want to lookup a string in this
I have an interface called Dictionary which has a method insert() . This interface
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
Say that i have a generic dictionary with data like this (I hope the
I have a class derived from Dictionary. I need this class to simulate a
I have a dictionary: a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 } I want to sort this
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
A Python dictionary is stored in no particular order (mappings have no order), e.g.
I have a dictionary containing the character positions of different fields in a string.

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.