luoyikun

导航

c# 遍历字典改key

    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,如果符合条件就新存入字典中,然后删除字典旧项

posted on 2017-12-13 02:26  luoyikun  阅读(8)  评论(0)    收藏  举报  来源