• 主页

  • 投资

  • IT

    🔥
  • 设计

  • 销售

  • 共151篇

    Unity - 游戏引擎

关闭

返回栏目

关闭

返回Unity - 游戏引擎栏目

61 - 配置 - Common公共码code DictTool字典工具

作者:

贺及楼

成为作者

更新日期:2024-05-11 12:12:37

新建字典文件夹Tools

解决方案资源管理器—解决方案“Common”—右键—添加—新建项—文件夹
命名为:

  1. Tools

新建字典文件DictTool

解决方案资源管理器—解决方案“Common”—Common—右键—添加—新建项—类库
命名为:

  1. DictTool.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Common.Tools
  5. {
  6. public class DictTool
  7. {
  8. public static T2 GetValue<T1, T2>(Dictionary<T1,T2> dict, T1 key)
  9. {
  10. T2 value;
  11. bool isSuccess = dict.TryGetValue(key, out value);
  12. if (isSuccess)
  13. {
  14. return value;
  15. }
  16. else
  17. {
  18. return default(T2);
  19. }
  20. }
  21. }
  22. }