0
0
C Sharp (C#)programming~15 mins

Action delegate type in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Action Delegate Type in C#
📖 Scenario: You are creating a simple program to greet users and show messages using the Action delegate type in C#. This helps you run small pieces of code stored in variables.
🎯 Goal: Build a program that stores greeting and farewell messages in Action delegates and runs them to display messages on the screen.
📋 What You'll Learn
Create an Action delegate variable called greet that prints a greeting message.
Create another Action delegate variable called farewell that prints a farewell message.
Invoke both greet and farewell to show the messages.
💡 Why This Matters
🌍 Real World
Using <code>Action</code> delegates helps you store and run small tasks or callbacks, like button clicks or timed events, in real programs.
💼 Career
Understanding delegates is important for event-driven programming and working with frameworks like Windows Forms, WPF, or ASP.NET.
Progress0 / 4 steps
1
Create an Action delegate called greet
Write a line of code to create an Action delegate variable named greet that prints "Hello, welcome!" when called.
C Sharp (C#)
Need a hint?

Use Action with a lambda expression that calls Console.WriteLine.

2
Create an Action delegate called farewell
Add a line of code to create an Action delegate variable named farewell that prints "Goodbye, see you soon!" when called.
C Sharp (C#)
Need a hint?

Use the same pattern as greet but with the farewell message.

3
Invoke the greet and farewell delegates
Write code to call the greet and farewell delegates to display their messages.
C Sharp (C#)
Need a hint?

Call each delegate by adding parentheses after their names.

4
Display the output
Run the program and write a line of code to print the output of calling greet and farewell delegates.
C Sharp (C#)
Need a hint?

The output appears automatically when you run the program because of the Console.WriteLine calls inside the delegates.