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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:56:53+00:00 2026-05-16T04:56:53+00:00

This is a general question, but here is the specific case I’m looking for

  • 0

This is a general question, but here is the specific case I’m looking for a solution to:

I have a Dictionary<int, List<string>> I want to apply various predicates to. I want one method that can take care of multiple LINQ queries such as these:

from x in Dictionary
where x.Value.Contains("Test")
select x.Key

from x in Dictionary
where x.Value.Contains("Test2")
select x.Key

So I’m looking for a method like so:

public int GetResult(**WhatGoesHere** filter)
{
    return from x in Dictionary.Where(filter)
           select x.Key;
}

To be used like so:

int result;

result = GetResult(x => x.Value.Contains("Test"));
result = GetResult(x => x.Value.Contains("Test2"));

What is the proper syntax for WhatGoesHere?

  • 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-16T04:56:54+00:00Added an answer on May 16, 2026 at 4:56 am

    You can use Func<KeyValuePair<int, List<string>>, bool>:

    public int GetResult(Func<KeyValuePair<int, List<string>>, bool> filter)
    {
        return (from x in Dictionary
                where filter(x)
                select x.Key).FirstOrDefault();
    }
    

    Or alternatively: Predicate<KeyValuePair<int, List<string>>>. I think Func which was introduced in .NET 3.5 is preferred these days.

    You are using x to mean two different things in your final example and this will give a compile error. Try changing one of the xs to something else:

    x = GetResult(y => y.Value.Contains("Test1"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a very specific question, but I'm looking for a slightly more general solution
This is more a general question but my particular case involves a ruby/rails app
This is a general question, but I'll explain my specific need at the moment:
This is a general question about MVC as a pattern, but in this case
I have a Yesod application (but question is more general than this) that allows
This might be a general mvp places and activities question, but the show case
This is a bit of a general question, but I will give a specific
This is a pretty general question, but the specific thing I'm doing is simple
Very specific question but we have some good Ada people here so I would
This question is general but I am going to give a specific example. The

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.