我正在使用以下扩展方法(来自现有的 StackOverflow 问题)将现有的可枚举拆分为两个:
public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, int parts)
{
int i = 0;
var splits = from item in list
group item by i++ % parts into part
select part.AsEnumerable();
return splits;
}
我正在使用这样的方法:
//accountIds is simply an IEnumerable<string>
var foo = accountIds.Split(2).ToList();
当我运行我的应用程序时,该方法似乎工作正常。但是,当我调试我的应用程序时,这行代码总是会引发异常:
Object reference not set to an instance of an object.
我很困惑为什么这个方法只在我调试时抛出异常。