Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.15 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C# Inline lambda evaluation
  2. bool foo_equals_bar = new Func<String, bool>(str => str.Equals("foo"))("bar");
  3.        
  4. bool foo_equals_bar = (str => str.Equals("foo"))("bar");
  5.        
  6. str => str == "A"
  7.        
  8. delegate (string str) { return str == "A";};
  9.        
  10. bool result = (str => str == "A")("B");
  11.        
  12. bool foo_equals_bar = "bar".Equals("foo");
  13.        
  14. bool foo_equals_bar = (str => str.Equals("foo"))("bar");
  15.        
  16. Expression<Func<string, bool>> a = str => str.Equals("foo");
  17. Expression<Predicate<string>> b = str => str.Equals("foo");
  18. Expression<Action<string>> c = str => str.Equals("foo");
  19. Func<string, bool> a1 = str => str.Equals("foo");
  20. Predicate<string> b1 = str => str.Equals("foo");
  21. Action<string> c1 = str => str.Equals("foo");
  22.        
  23. public static class Functional
  24. {
  25.     public static Func<TResult> Lambda<TResult>(Func<TResult> func)
  26.     {
  27.         return func;
  28.     }
  29.  
  30.     public static Func<T, TResult> Lambda<T, TResult>(Func<T, TResult> func)
  31.     {
  32.         return func;
  33.     }
  34.  
  35.     public static Func<T1, T2, TResult> Lambda<T1, T2, TResult>(Func<T1, T2, TResult> func)
  36.     {
  37.         return func;
  38.     }
  39. }
  40.        
  41. bool foo_equals_bar = Functional.Lambda(str => str.Equals("foo"))("bar");