嘗試根據key得到value,得到了的話直接返回value,沒有得到直接返回null
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// 對Dictory的擴展
/// </summary>
public static class DictionaryExtension {
/// <summary>
/// 嘗試根據key得到value,得到了的話直接返回value,沒有得到直接返回null
/// this Dictionary<Tkey,Tvalue> dict 這個字典表示我們要獲取值的字典
/// </summary>
public static Tvalue TryGet<Tkey, Tvalue>(this Dictionary<Tkey, Tvalue> dict, Tkey key)
{
Tvalue value;
dict.TryGetValue(key, out value);
return value;
}
}