IDictionary遍历删除

来源:互联网 发布:诈骗软件怎么举报 编辑:程序博客网 时间:2024/06/10 21:27
Dictionary<string, string> Menu = new Dictionary<string, string>();            Menu.Add("1", "helo");            Menu.Add("2", "helo");            Menu.Add("3", "helo");            Menu.Add("4", "helo");                       //要保留的            string[] strMenu = new string[] { "4"};            //初始化key数组            string[] MenuKeys = new string[Menu.Count];            //取出key到数组            Menu.Keys.CopyTo(MenuKeys, 0);            foreach (string key in MenuKeys)            {                //要保留的 不包含 key,则删除                if (!strMenu.Contains(key))                    Menu.Remove(key);            }

0 0
原创粉丝点击