delegate with multiple arguments

We can also declare a delegate to receive multiple arguments

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

namespace ConsoleApplication10
{
    class Program
    {
        delegate double GetInt(int num);
        delegate void ShowInt(int num);
        delegate void MultipleArguments(int num1, int num2);

        static void Main(string[] args)
        {
            GetInt mydelegate = Program.getValue;
            double ans = mydelegate(45);
            Console.WriteLine(ans);

            ShowInt myintdelegate = Program.getInt;
            myintdelegate(100);

            MultipleArguments multarg = Program.setMultipleArgs;
            multarg(30, 40);
        }

        static double getValue(int num)
        {
            double x = num * 0.15;
            return x;
        }

        static void getInt(int num)
        {
            Console.WriteLine(num);
        }

        static void setMultipleArgs(int num1, int num2)
        {
            Console.WriteLine("{0}, {1}", num1, num2);
        }
    }
}

 

Tags:,

Add a Comment

Your email address will not be published. Required fields are marked *