c# 遍历字典改key

来源:互联网 发布:淘宝滞销率怎么算 编辑:程序博客网 时间:2024/06/05 07:16
    void test(int cur, int cnt)    {        List<string> list = new List<string>(m_pptData.dicPpt.Keys);        foreach (string key in list)        {            if (int.Parse(key) > cur)            {                int newId = int.Parse(key) + cnt;                m_pptData.dicPpt.Add(newId.ToString(), m_pptData.dicPpt[key]);                m_pptData.dicPpt.Remove(key);            }        }    }

1.把key 存到一个list中
2.遍历list,如果符合条件就新存入字典中,然后删除字典旧项

原创粉丝点击