![]() | ![]() |
Parameterized methods are the type of methods that have some parameters. The parameters are used to pass data to the methods. There is no limit on the number and types of the parameters. When the function is called, the values for the parameters are required to be passed with the function call. It is important to mention that the number, order, and type of the parameters in the function call and the function declaration must match.
Let’s declare a function that accepts two integer type parameters. The first parameter is the amount and the second parameter is the percentage of the tax on that amount. The function value for the tax percentage and then prints that on the screen. Look at the following script:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyProgram
{
class Program
{
static void Main(string[] args)
{
PrintTax(125, 20);
Console.ReadKey();
}
public static void PrintTax(float amount, float percentage)
{
float tax = (percentage * amount) / 100;
Console.WriteLine(tax);
}
}
}
In the script above, we declare a function called PrintTax(), which accepts two float type parameters: amount and percentage. Inside the function, the percentage of tax is calculated and printed using the Console function.
In the function call to the PrintTax() function, the values for both the parameters are passed. The value for the amount is 125 and for percentage is 20. In the result, you will see 25 since 20% of 125 is 25 as shown below: