Addition Method Within Main Class by Calling method In C#

The method definition specifies the names and types of any parameters that are required. When calling code calls the method, it provides concrete values called arguments for each parameter. The arguments must be compatible with the parameter type but the argument name (if any) used in the calling code does not have to be the same as the parameter name defined in the method.

using System;  
class MethodCalling  
    public static void Main(string[] args)   
        int value1 = 0, value2 = 0;  
        int total = 0;  
        Console.Write("Enter first value: ");  
        value1 = Convert.ToInt32(Console.ReadLine());  
        Console.Write("Enter second value: ");  
        value2 = Convert.ToInt32(Console.ReadLine());  
        total = addition(value1, value2);  
        Console.WriteLine("Total of {0} and {1} is {2}", value1, value2, total);  
    static int addition(int x, int y)   
        return x + y;  
Enter first value: 4
Enter second value: 5
Total of 4 and 5 is 9

0 Comment's

Comment Form