c# 字典dictionary 1个key键对应多个值得方法-MultiDictionary
c# 字典dictionary 1个key键对应多个值得方法-MultiDictionary
source_to_recipe.txt
source1,11 source1,22 source2,33 source3,55
Dictionary<string, List<string>> multi_dic = new Dictionary<string, List<string>>(); string[] recipe_array = File.ReadAllLines("source_to_recipe.txt"); foreach(string str2 in recipe_array) { if (str2.Contains(",")==true) { string[] source_recipe = str2.Split(','); if(source_recipe.Length!=2) { MessageBox.Show("recipe配置文件错误", "WaferSawRouteInspection"); AddToMainWindowLog("#recipe配置文件错误"); return; } if(multi_dic.ContainsKey(source_recipe[0])) { multi_dic[source_recipe[0]].Add(source_recipe[1]); } else { List<string> list_sub_value = new List<string>(); list_sub_value.Add(source_recipe[1]); multi_dic.Add(source_recipe[0], list_sub_value); } List<string> aa = multi_dic["source1"]; } }
欢迎讨论,相互学习。
cdtxw@foxmail.com