declaring methods with multiple parameters
1 // Fig. 7.2: MaximumFinder.cs
2 // Method Maximum with three parameters.
3 using System;
4
5 class MaximumFinder
6 {
7 // obtain three floating-point values and determine maximum value
8 static void Main()
9 {
10 // prompt for and input three floating-point values
11 Console.Write("Enter first floating-point value: ");
12 double number1 = double.Parse(Console.ReadLine());
13 Console.Write("Enter second floating-point value: ");
14 double number2 = double.Parse(Console.ReadLine());
15 Console.Write("Enter third floating-point value: ");
16 double number3 = double.Parse(Console.ReadLine());
17
18 // determine the maximum of three values
19 double result = Maximum(number1, number2, number3);
20
21 // display maximum value
22 Console.WriteLine("Maximum is: " + result);
23 }
24
25 // returns the maximum of its three double parameters
26 static double Maximum(double x, double y, double z)
27 {
28 double maximumValue = x; // assume x is the largest to start
29
30 // determine whether y is greater than maximumValue
31 if (y > maximumValue)
32 {
33 maximumValue = y;
34 }
35
36 // determine whether z is greater than maximumValue
37 if (z > maximumValue)
38 {
39 maximumValue = z;
40 }
41
42 return maximumValue;
43 }
44 }