What is Method Parameters With Example Code

Method parameters, also known as arguments, are values that are passed to a method when
it is called. Parameters allow methods to accept input data,
which can then be used within the method's body to perform specific tasks.
In C#, parameters are declared within the parentheses following the method name.




using System;
 
class Program
{
    static void Main(string[] args)
    {
        // Call the PrintMessage method with a string parameter
        PrintMessage("Hello, World!");
 
        // Call the AddNumbers method with two integer parameters
        int sum = AddNumbers(5, 7);
        Console.WriteLine("Sum of numbers: " + sum);
 
        // Call the MultiplyNumbers method with two integer parameters
        int product = MultiplyNumbers(3, 4);
        Console.WriteLine("Product of numbers: " + product);
    }
 
    // Method that takes a string parameter and prints it to the console
    static void PrintMessage(string message)
    {
        Console.WriteLine(message);
    }
 
    // Method that takes two integer parameters, adds them together, and returns the result
    static int AddNumbers(int num1, int num2)
    {
        return num1 + num2;
    }
 
    // Method that takes two integer parameters, multiplies them, and returns the result
    static int MultiplyNumbers(int num1, int num2)
    {
        return num1 * num2;
    }
}