foreach抛出BadImageFormatException

时间:2018-05-30 12:41:01

标签: c# .net exception

我有字段private Dictionary<int, List<T>> items;

的泛型类

在这种情况下我收到异常感到震惊,我一直在使用这种逻辑编程,但今天它没有“正常”工作

以下示例到达LOG 1并且我得到BadImageFormatException,但为什么?

class MyClass2<T> where T : MyClass1
{
private Dictionary<int, List<T>> items;

public List<T> GetAll()
{
    var result = new List<T>();
    if (items != null )
    {
        //LOG 1
        foreach (int key in this.items.Keys)
        {
            //LOG 2
            var value = this.items[key];
            if (value != null && value.Count > 0)
            {
                result.AddRange(value);
            }
        }
        //LOG 3
    }    
    return result;
}
}

我用以下代码foreach (int key in this.items.Keys.ToList())解决了这个问题,但解释了为什么会发生这种情况

0 个答案:

没有答案
相关问题