-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.cs
33 lines (28 loc) · 894 Bytes
/
action.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
class ActionDemo
{
static void Main(string[] args)
{
// 1. Using a named method
Action namedMethodAction = NamedMethod;
namedMethodAction();
// 2. Using an anonymous method
Action anonymousMethodAction = delegate
{
Console.WriteLine("Anonymous Method Action");
};
anonymousMethodAction();
// 3. Using a lambda expression
Action lambdaAction = () => Console.WriteLine("Lambda Action");
lambdaAction();
// 4. Using Action with parameters
Action<int, string> actionWithParams = (num, text) =>
Console.WriteLine($"Number: {num}, Text: {text}");
actionWithParams(10, "Hello");
}
// named method used for first Action instance on line 10
static void NamedMethod()
{
Console.WriteLine("Named Method Action");
}
}