Concept Flow - Action delegate type
Define Action delegate
Assign method or lambda
Invoke Action
Execute method body
Finish
The Action delegate holds a method reference with no return value and can be invoked to run that method.
Action<string> greet = name => Console.WriteLine($"Hello, {name}!"); greet("Alice");
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Define Action delegate 'greet' | Action<string> greet = lambda | greet holds reference to lambda |
| 2 | Invoke greet with "Alice" | greet("Alice") | Calls lambda with name="Alice" |
| 3 | Execute lambda body | Console.WriteLine($"Hello, {name}!") | Prints: Hello, Alice! |
| 4 | End of program | No more code | Program finishes |
| Variable | Start | After 1 | After 2 | Final |
|---|---|---|---|---|
| greet | null | lambda reference | lambda reference | lambda reference |
| name | undefined | undefined | "Alice" | undefined after call |
Action delegate type: - Represents a method with no return value (void) - Can take parameters (e.g., Action<string>) - Assigned with method or lambda - Invoked like a method - Used for callbacks or simple actions