๋ธ๋ฆฌ๊ฒ์ดํธ ์ฌ์ฉ ์์  ์ฝ๋
using System.Collections;
namespace DelegateEx
{   
    delegate int MyDelegate(int a, int b);
    class SumSubtract
    {
        public int sum(int a, int b)
        {
            return a + b;
        }
        public static int subtract(int a, int b) 
        // ๋ธ๋ฆฌ๊ฒ์ดํธ๋ static ๋ฉ์๋๋ ์ ๋ฌํ  ์ ์๋ค. 
        {
            return a - b;
        }
        // ๋ธ๋ฆฌ๊ฒ์ดํธ(delegate = ๋๋ฆฌ์)๋ ํด๋น ๋ฉ์๋๋ค์ด ์ ์ฅ๋์ด ์๋ ์ฃผ์๊ฐ์ ๋๊ฒจ์ฃผ๋ ๊ฒ์ด๋ค.
    }
    class Program
    {
        static void Main(string[] args)
        {
            SumSubtract ss = new SumSubtract();
            MyDelegate md1 = new MyDelegate(ss.sum);
            Console.WriteLine(md1(1, 2));
            MyDelegate md2 = new MyDelegate(SumSubtract.subtract);
            Console.WriteLine(md2(10, 2));
        }
    }
}
Output
3
8
- ๋ธ๋ฆฌ๊ฒ์ดํธ๋ static ๋ฉ์๋๋ ์ ๋ฌํ  ์ ์๋ค. 
 
- ๋ธ๋ฆฌ๊ฒ์ดํธ(delegate = ๋๋ฆฌ์)๋ ํด๋น ๋ฉ์๋๋ค์ด ์ ์ฅ๋์ด ์๋ ์ฃผ์๊ฐ์ ๋๊ฒจ์ฃผ๋ ๊ฒ์ด๋ค.
 
- subtract ๋ฉ์๋์ ๊ฐ์ด static ์ด ๋ถ์ผ๋ฉด ์ธ์คํด์ค์ ๋ฉค๋ฒ๊ฐ ์๋ ํด๋์ค์ ๋ฉค๋ฒ์ด๊ธฐ์ ํด๋์ค๋ฅผ ํตํด ํธ์ถํด์ผํ๋ค. 
 
โญ๏ธโญ๏ธโญ๏ธ Delegate์ ์ฌ์ฉ์ด์ 
- โญ๏ธโญ๏ธโญ๏ธ ์๋ ์ฝ๋๋ฅผ ํตํด ์ ์ฌ์ฉํ๋์ง ์ดํดํ๊ณ  ๊ทธ๋ฆฌ๊ณ  Bubble Sort์ ๋ํด์๋ ์๊ธฐํ๋ค.
 
using System.Collections;
namespace DelegateEx
{
    delegate int select_sort_type(int a, int b);
    class Program
    {   
        static int Ascending(int a, int b)
        {
            if (a > b)
            {
                return 1;
            }
            else if(a == b)
            {
                return 0;
            }
            else
            {
                return -1;
            }
        }
        static int Descending(int a, int b)
        {
            if (a < b)
            {
                return 1;
            }
            else if (a == b)
            {
                return 0;
            }
            else
            {
                return -1;
            }
        }
        //๋ฒ๋ธ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ
        static void BubbleSort(int[] Array1, select_sort_type sortType)
        {
            int temp = 0;
            for (int i = 0; i < Array1.Length - 1; i++)
            {
                for (int j = 0;  j < Array1.Length - (i+1); j++)
                {
                    if (sortType(Array1[j],Array1[j+1]) > 0)
                    {
                        temp = Array1[j];
                        Array1[j] = Array1[j+1];
                        Array1[j+1] = temp;
                    } 
                }
            }
        }
        static void Main(string[] args)
        {   
            int[] arr = { 12, 11, 33, 14, 5, 16, 7, 82, 9, 10, 11, 12 };
            BubbleSort(arr,new select_sort_type(Ascending));
            Console.WriteLine($"---------------------์ค๋ฆ์ฐจ์ ์ ๋ ฌ-----------------------");
            foreach(int i in arr)
            {
                Console.WriteLine($"{i} ");
            }
            Console.WriteLine();
            Console.WriteLine($"---------------------๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ-----------------------");
            //์ด๋ ๊ฒ ๋น์ทํ๊ฒ > < ์ฐ์ฐ๋ง ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ ์ฝ๋๋ฅผ ๊ณ์ํด์ ๋ด๋ถ ํจ์๋ฅผ ๊ณ ์ณ์ค๊ฐ๋ฉฐ ์ค๋ฆ์ฐจ์๊ณผ ๋ด๋ฆผ์ฐจ์์ ๋ฐ๊ฟ์ผ ํ ๊น?
            //๋ถํธํ๋ค. ์ด๋ด๋ ๋ธ๋ฆฌ๊ฒ์ดํธ๋ฅผ ์ ์ํด์ ํด๊ฒฐํ  ์ ์๋ค.
            BubbleSort(arr, new select_sort_type(Descending));
            foreach (int i in arr)
            {
                Console.WriteLine($"{i} ");
            }
        }
    }
}
Output
---------------------์ค๋ฆ์ฐจ์ ์ ๋ ฌ-----------------------
5
7
9
10
11
11
12
12
14
16
33
82
---------------------๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ-----------------------
82
33
16
14
12
12
11
11
10
9
7
5
- ๋จ์ํ๊ฒ ๋ค๋ฅธ ๋ฉ์๋์ ๋ฉ์๋๋ฅผ ์ ๋ฌํ์ง๋ง, ์ด๋ฒ ์ฝ๋์์์ฒ๋ผ ์ค๋ฆ์ฐจ์ ๋ด๋ฆผ์ฐจ์์ ๋ํ ๋ก์ง์ ์์ฑํ  ํ์์์ด ๊ตฌํ์ด ๊ฐ๋ฅํ๋ค.