parent
ea54dc68fb
commit
5977ac2edd
@ -0,0 +1,28 @@ |
||||
namespace DevTips.Tips |
||||
{ |
||||
class ActionClient |
||||
{ |
||||
public static void Client() |
||||
{ |
||||
// Default |
||||
Action<string> act = Output; |
||||
act("Hello"); |
||||
|
||||
// Ananymous method |
||||
Action<string, string> act2 = delegate (string msg, string title) |
||||
{ |
||||
System.Console.WriteLine($"[{title}] msg"); |
||||
}; |
||||
act2("No data found", "Error"); |
||||
|
||||
// Lambda |
||||
Action<int> act3 = (code) => Console.WriteLine($"Code: {code}"); |
||||
act3(505); |
||||
} |
||||
|
||||
private static void Output(string msg) |
||||
{ |
||||
System.Console.WriteLine(msg); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
namespace DevTips.Tips |
||||
{ |
||||
class FuncClient |
||||
{ |
||||
private static int _state; |
||||
|
||||
public static void Client() |
||||
{ |
||||
// Default |
||||
Func<bool> func1 = IsValid; |
||||
System.Console.WriteLine(func1()); |
||||
|
||||
// Ananymous method |
||||
Func<bool> func2 = delegate |
||||
{ |
||||
return _state == 0; |
||||
}; |
||||
System.Console.WriteLine(func2()); |
||||
|
||||
|
||||
// Lambda |
||||
Func<bool> func3 = () => _state == 0; |
||||
System.Console.WriteLine(func3()); |
||||
|
||||
} |
||||
|
||||
private static bool IsValid() |
||||
{ |
||||
return _state == 0; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue