Delegate in C#

Delegate

What is delegation?

If I understand it personally, delegation is equivalent to a pointer in C language, and it can also be understood as a class. Baidu's definition is


 

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

namespace Weituo_ShiJian
{

    //define a delegate
    public delegate void AppearanceDelegate(string Appearance);

    class program
    {
        //define a method
        private static void Method(string Appearance)
        {
            Console.WriteLine("Your appearance is very: " + Appearance);

        }
        static void Main(string [] args)
        {
            //Instantiate the delegate and initialize
            AppearanceDelegate appDelegate = new AppearanceDelegate(Method);
            Method("Handsome!");
            Console.ReadKey();
        }

    }

}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325347362&siteId=291194637