1. 程式人生 > >【C#】C#委託和字典的結合使用

【C#】C#委託和字典的結合使用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DelegateDic : MonoBehaviour
{

    public delegate void del_Value(string name);
    public Dictionary<string, del_Value> dic_Test;

    void Start()
    {
        dic_Test = new Dictionary<string, del_Value>();
        if (!dic_Test.ContainsKey("lidongyang"))
        {
            dic_Test.Add("lidongyang",null);
        }
        dic_Test["lidongyang"] += test01;
        dic_Test["lidongyang"] += test02;
        dic_Test["lidongyang"] += test03;
        dic_Test["lidongyang"]("Love");

    }

    public void test01(string name)
    {
        print("test01" + name);
    }

    public void test02(string name)
    {
        print("test02" + name);
    }
    public void test03(string name)
    {
        print("test03" + name);
    }


}



參考 :http://blog.csdn.net/qq_15267341/article/details/60462943