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

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.39 KB  |  hits: 10  |  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. Using C# delegates with methods with optional parameters
  2. delegate int Del(int x);
  3.  
  4. static int Foo(int a, int b = 123)
  5. {
  6.     return a+b;
  7. }
  8.  
  9. static void Main()
  10. {
  11.     Del d = Foo;
  12. }
  13.        
  14. delegate int Del(int x, int y = 123);
  15.        
  16. delegate int Del(int x, int y = 456);
  17.  
  18. static int Foo(int a, int b = 123)
  19. {
  20.     return a+b;
  21. }
  22.  
  23. static void Main()
  24. {
  25.     Del d = Foo;
  26.  
  27.     Console.WriteLine(d(1));
  28. }