private Dictionary<string, SortedSet<string>> MergeIdenticalKey(Dictionary<string, SortedSet<string>> dic,
            string key,
            SortedSet<string> set)
        {
            if (set == null || set.Count == 0 || string.IsNullOrEmpty(key)) return dic;
            SortedSet<string> sortedSet = null;
            if (dic.ContainsKey(key))//包含重复key
            {
                foreach (KeyValuePair<string, SortedSet<string>> item in dic)
                {
                    if (item.Key == key)
                    {
                        string strFldval = null;
                        foreach (string myValues in item.Value)
                            strFldval += myValues + ",";
                        foreach (string str in set)
                            strFldval += str + ",";
                        dic.Remove(key);
                        sortedSet = new SortedSet<string>(strFldval.Split(',').FirstOrDefault() == "" ?
                            strFldval.Split(',')
                            : strFldval.Split(',').Take(strFldval.Split(',').Length - 1)); //task(2), 去掉空字符
                        dic.Add(key, sortedSet);
                        break;
                    }
                }
            }
            else //不包含直接添加
                dic.Add(key, set);
            return dic;
        }

  

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2021-12-15
  • 2021-06-21
  • 2021-08-14
  • 2021-09-25
  • 2021-09-14
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案