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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:20:12+00:00 2026-05-23T16:20:12+00:00

I have the following method definition (EDITED to remove redundant generic): public static T

  • 0

I have the following method definition (EDITED to remove redundant generic):

public static T SearchAgaistValues<T>(Dictionary<string, string> input, 
string key, List<T> values, Predicate<T> match, out string[] cmdParams)

My simplified requirements are as follows. I need to search input for key, and if found, see if its value appears in values. However, values is generic (and will obviously contain a string that I need to match). Therefore, the way I see it, I have to pass a predicate method to perform the matching.

However, every example of Predicate<T> I have seen has a hard coded comparitor. I need to compare the found key's value to each item in values. I cannot pass these values, however.

I can’t see how to do this outside of a foreach loop with a delegate based match method.

Am I missing something here?

  • 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-23T16:20:12+00:00Added an answer on May 23, 2026 at 4:20 pm

    As I see it you have two options, without changing crazy requirements.

    Option 1 is to use Func<string, T1, bool> instead of Predicate<T1>. This way the predicate can convert between string and T1 as needed and return the boolean matched result.

    public static T1 SearchAgaistValues<T, T1>(
                Dictionary<string, string> input, 
                string key, 
                List<T1> values, 
                Func<string, T1, bool> match, 
                out string[] cmdParams)
    

    Alternatively you can pass an additional Converter<T1, string> parameter to convert the looked-up string to a T1 and then compare using the predicate.

    public static T1 SearchAgaistValues<T, T1>(
                Dictionary<string, string> input, 
                string key, 
                List<T1> values, 
                Converter<T1, string> converter,
                Predicate<T1> match, 
                out string[] cmdParams)
    

    Both cases are less than ideal though. This function sounds a lot more like a problem looking for a solution than the other way around. The signature is a bit crazy and seems like it can be greatly simplified by restating the requirements or breaking it up into pieces.

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

Sidebar

Related Questions

I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
I have the following method: public static string UlList(this HtmlHelper helper, List<IEntity> entities, string
I have the following query method that has slow performance: @Override public Map<String, Long>
I have the following error message: 'System.Collections.Generic.Dictionary<int,SpoofClass>' does not contain a definition for 'biff'
I have a the following method definition in my class: virtual Calc* Compile( Evaluator*
I have a COM interface with a following method definition (IDL notation): SCODE GetText( [in,
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have the following method that is supposed to be a generic Save to
I have the following method and interface: public object ProcessRules(List<IRule> rules) { foreach(IRule rule
I have the following method: public bool IsValid { get { return (GetRuleViolations().Count() ==

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.