Skip to main content

C#: Program #49(Delegates)

using System;


namespace DelegatesCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Arithmetic method1,method2,combine;
            method1=new Arithmetic(add);
            method2=new Arithmetic(subtract);
            combine = method1 + method2;

            combine(10,8);
            Console.ReadKey();


        }
        public delegate void Arithmetic(double no1,double no2);
        public static void add(double num1, double num2)
        {
            Console.WriteLine(num1+num2);
        }
        public static void subtract(double number1, double number2)
        {
            Console.WriteLine(number1 - number2);
        }
    }
}

Comments

Popular posts from this blog

C#: Program #15 (For Loop)

using System; namespace Loops {     class Program     {         static void Main(string[] args)         {                         object[] information = {"Gray", "14-Arid-4052", "Rawalpindi",21,3.80};             for (int i = 0; i < information.Length; i++)             {                 Console.WriteLine("The value of index {0} is {1}",i,information[i]);             }                 Console.ReadKey();         }     } }