Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi , Can some one help me to convert this Delegate program method to anonymous method

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

namespace Delgates_Ex1
{

    public delegate void ExampleDelgate(int x, int y);


    class Democlass
    {
        public void Add(int x, int y)
        {

            Console.WriteLine(x+y);
            

        }

    }


    class Program
    {
      


        static void Main(string[] args)
        {
            Democlass d = new Democlass();

            ExampleDelgate e1 = new ExampleDelgate(d.Add); 


            e1(20, 10);  
        }
    }
}
Posted

Here you are (see MSDN[^])
C#
static void Main(string[] args)
{
  Democlass d = new Democlass();

  ExampleDelgate e1 = new ExampleDelgate(d.Add);
  ExampleDelgate e2 = delegate(int x, int y){ Console.WriteLine(x+y);}; // anonymous method

  e1(20, 10);
  e2(20, 10);
}
 
Share this answer
 
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900