c# - Method with Predicate as Parameter -


This is a common question, but here's a special case that I'm looking for a solution:

I have a dictionary & lt; Int, list & lt; String & gt; & Gt; I would like a method for various predicates which is that many LINQ queries such as:

  in X in X where x.Value.Contains ("Test") is X in X Select X Select X.Value.Contains ("Test2"). X.Key  

So I'm looking for a method like this:

  Public int GetResult (** WhatGoesHere ** Filters) {Return in Dictionary in X. Choose where (filter) x. KA; }  

To do this:

  Full results; Results = GetResult (x => x.Value.Contains ("Test")); Results = GetResult (x => x.Value.Contains ("Test 2"));  

WhatGoesHere

You can Func & lt; KeyValuePair & lt; Int, list & lt; String & gt; & Gt;, bool & gt; :

  public int GetResult (Func & lt; KeyValuePair  

Or alternatively: Reverted & lt; Keyvaluepair & lt; Int, list & lt; String & gt; & Gt; I think the Func which was introduced in .NET 3.5 is the day.

You are using x , which means two different things in your last example and it will give a compilation error x s Try changing one of the following:

  x = GetResult (y = & gt; y.Value.Contains ("Test1"));  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -