Thursday, 25 May 2017

What is Method or Function in C#?

In C# method is a collection of statements that are grouped together to perform an operation for a particular task. A class can have any no. of method or function. Method is also called function with the help of method or function we can easily find error of the program and their logic.





Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Example1
{
    class calculation
    {
        static int num1, num2, result;

        public static void add()  // method or function
        {
            Console.Write("Enter number  num1 value ");
            num1 = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter number Num2 value ");
            num2 = Convert.ToInt32(Console.ReadLine());

            result = num1 + num2;

            Console.Write("\n Addition result={0}", result);
            Console.ReadLine();
        }

    
    }
    class Program
    {
        static void Main(string[] args)
        {
            calculation.add();
            
            Console.Read();
        }
    }
}

Output:




Share this


0 Comments

Advertisement