表驱动法
查询表(ookup table)
...
Dictionary<string, bool> testDict = new Dictionary<string, bool>(){ ["key1"] = true, ["key2"] = false, ["测试"] = true};
...
if ( testDict.ContainsKey("测试"))//通过int变量 来查找 对应 的字符串
{
bool value_ = false;
value_ = test_array["测试"];
//Console.WriteLine(value);
Debug.Log(value_);//输出:true
}//
...
Dictionary<string, int> testDict1 = new Dictionary<string, int>(){ ["key1"] = 2, ["key2"] = 1, ["测试"] = 0};//不同的数值代表不同的含义
...
if ( testDict.ContainsKey("测试"))//通过int变量 来查找 对应 的字符串
{
int value_ = false;
value_ = test_array["测试"];
//Console.WriteLine(value);
Debug.Log(value_);//输出:true
}//
...

本文探讨了如何使用C#的Dictionary数据结构,通过字符串和整数键值对实现表驱动法。通过testDict和testDict1实例展示如何通过不同类型的键查找对应的值,并以Unity3D和Python示例说明其在不同领域的应用。
1634

被折叠的 条评论
为什么被折叠?



