Dan*_*jir 2 c# regex ienumerator dispose idisposable
我试图将这些函数称为摆脱我不需要的东西,但我的代码似乎在我开始认为是徒劳的挣扎中击败了我.我已经尝试了多种方法来解决最后两个错误,但IEnumerator给了我外卡.错误在行:if(enumerator2是IDisposable)和if(枚举器是IDisposable)
try
{
enumerator = matchs.GetEnumerator();
while (enumerator.MoveNext())
{
IEnumerator enumerator2;
Match current = (Match) enumerator.Current;
num = 0;
try
{
enumerator2 = current.Groups.GetEnumerator();
while (enumerator2.MoveNext())
{
Group group = (Group) enumerator2.Current;
strArray[num, num3] = group.Value;
num++;
}
}
finally
{
if (enumerator2 is IDisposable)
{
(enumerator2 as IDisposable).Dispose();
}
}
if (num2 < num3)
{
num2 = num3;
}
num3++;
}
}
finally
{
if (enumerator is IDisposable)
{
(enumerator as IDisposable).Dispose();
}
}
strArray[num, 0] = Conversions.ToString((int) (num2 + 1));
return strArray;
}
Run Code Online (Sandbox Code Playgroud)
编辑 - 特定错误消息:使用未分配的局部变量'enumerator2'
使用未分配的局部变量'enumerator'
使用for-each循环而不是while循环.如果需要,它会为您调用Dispose.
http://msdn.microsoft.com/en-us/library/aa288257(VS.71).aspx
| 归档时间: |
|
| 查看次数: |
1890 次 |
| 最近记录: |