Exercise
Function With Parameters
Objective
Write a C# program whose Main must be like this:
public static void Main()
{
SayHello("John");
SayGoodbye();
}
SayHello and SayGoodbye are functions that you must define and that will be called from inside Main. As you can see in the example. SayHello must accept an string as a parameter.
Write Your C# Exercise
C# Exercise Example
// Importing the System namespace to access basic system functions
using System;
class Program
{
// Function to print a greeting message with a name as a parameter
public static void SayHello(string name)
{
// Output a greeting message with the user's name
Console.WriteLine($"Hello, {name}! Welcome to the program.");
}
// Function to print a farewell message
public static void SayGoodbye()
{
// Output a farewell message
Console.WriteLine("Goodbye, thanks for using the program!");
}
// Main method to call SayHello and SayGoodbye functions
public static void Main()
{
// Call the SayHello function with "John" as the parameter
SayHello("John");
// Call the SayGoodbye function to bid farewell to the user
SayGoodbye();
}
}