Static Addition Method Within Main Class C# with Example



Static Addition Method Within Main Class C# with Example

 using System;

namespace CSharpFundamentals
{
    class StaticAdditionMethodWithinMainClass
    {
        private static void Main(string[] args)
        {
            int value1, value2, total;

            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;
        }
    }
}
 

0 Comment's

Comment Form