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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:19:19+00:00 2026-05-25T00:19:19+00:00

I have a collection like this: IEnumerable<Query> queries; I am searching for the ones

  • 0

I have a collection like this:

IEnumerable<Query> queries;

I am searching for the ones contained in keys of a dictionary and I want to do something on matching value.I know this is possible:

(from query in queries
where _metadata.ContainsKey(query.Value)
select query).ToList().ForEach(result=>_metadata[result.Value].AddQuery(result));

I wonder if I could make it simpler by calling AddQuery() in matching query enumerations. Query is immutable, so it should not break it.It should be something like this.

from query in queries
where _metadata.ContainsKey(query.Value)
//do something like _metadata[query.Value].AddQuery(query)
  • 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-25T00:19:20+00:00Added an answer on May 25, 2026 at 12:19 am

    Why not just do:

    foreach (var query = queries.Where(q => _metadata.ContainsKey(query.Value)))
    {
        _metadata[query.Value].AddQuery(query)
    }
    

    You can provide lambdas to Select, Where etc which have side-effects – but it’s generally a bad idea; LINQ queries are meant to be stateless, ideally – you should be able to iterate over the query multiple times with no problems. Here, we’ve clearly separated the side-effect (adding a query to _metadata) from the query.

    Note that the above code still works slightly differently to your original though, due to the way Where is executed – each new query will be added before the remaining Where predicates are executed. In other words, although your query itself is side-effect free, the side-effect you’re introducing has an impact on the query.

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

Sidebar

Related Questions

I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I have a collection testcase like this, Test Builds have many Test Case Logs
I have a collection class like this: public class SomeDataCollection : List<ISomeData> { //
Suppose I have a collection of files like this: echo -e apple\n cherry >>
I have a collection of MODS records that looks like this: <modsCollection> <mods [namespaces
I have a collection of entities with an any-association, like this: public class CreatedLog
The situation is like this: I have an Observable Collection that has a bunch
I have some code that looks like this: foreach(var obj in collection) { try
I have a variable with a jQuery collection in it, like this: $collection =
i have a collection of cars. I want to bucket this into separate lists

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.