zoukankan      html  css  js  c++  java
  • C#List或者Set集合相同的key合并Value的值

            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;
            }
    

      

  • 相关阅读:
    GenericServlet vs HttpServlet
    il c井
    额。。万恶之源就是c
    js算数优先级
    connect-flash 中间件
    触发bfd 的条件
    module 和 module.exports 的区别
    a标签填充父容器
    bootstrap
    每日一练排版
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/12585498.html
Copyright © 2011-2022 走看看