c# - Help with Predicate<T> delegate -


I am trying to create an overloaded ad using an ordered class as an extension, and some key based values On.

The calling code will look like this:

  OrderDocument = New ordered design (); Prediction & lt; Int> lessThan5 = i =>; I & lt; 5; Hint & lt; String> lenOf2 = s => s.length == 2; Dict.Add ("01", "name", lessThan5); Dict.Add ("02", "Location", lenOf2);  

I have created an extension method like this:

  public static class collection extension {add public static zero (this ordered objects, string , String v, predicate p) {if (p) {d.Add (k, v); }}}  

But this does not work because I can not seem to "bool" in reading a compiler error.

Does anybody know what I am missing?

Thanks for any help - Katha

The problem is that you Are not checking to evaluate the predictions and see if the predicate is satisfied. Now, this is not clear from your question. If you want to test the key or value, check the following: You should also consider that the method should be returned to the bool success or failure Indicates as I did. Static class OrderedDictionaryExtensions {add public static bolt (this OrderedDictionary dictionary, string key, string value, predicate & lt; string & gt; count) {if (dictionary == empty) {new logic: NullException ("Dictionary"); } If (decided == faucet) {new argument NullException ("predicate"); } If (built (key)) {dictionary.Add (key, value); Back true; } return false; }}

use;

  // dictionary isderedDictionary dictionary.Add ("key", "value", s = & gt; s.Length & lt; 5);  

You can actually make this bit normal because OrderedDictionary is not strongly-typed.

  Fixed class OrderedDictionaryExtensions {public static bool & Lt; TKey, TValuue & gt; (This ordered dictionary, key of vaccine, TV value, launch & amp;; TKey & gt ;;) (if (dictionary == empty) {New logic: NullException ("dictionary");} If (determination == Null] {New argument NullException ("predicate");} If (built (key)) {dictionary.Add (key, value); return true;} description is false;}}  
< P> Usage:

  // dictionary isderedDictionary dictionary.Add (17, "hello, world!", I => i% 2! = 0);  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -