c#字典的一个错误使用

来源:互联网 发布:人体工程学鼠标 知乎 编辑:程序博客网 时间:2024/05/22 02:09
using System;using System.Collections.Generic;public class Test{    public static void Main()    {        Dictionary<int, int> data = new Dictionary<int, int>() { { 100, 20 }, { 120, 20 }, { 1293, 30 }};        data.Remove(100);        Console.WriteLine(data.Count);        for (int i = 0; i < data.Count; ++i )             Console.WriteLine(data[i]);    }}

错误:提示未找到指定key
Remove和for不能共存,尽量使用foreach.

0 0
原创粉丝点击