我试图退出 using 语句,同时停留在封闭的 for 循环中。例如。
for (int i = _from; i <= _to; i++)
{
try
{
using (TransactionScope scope = new TransactionScope())
{
if (condition is true)
{
// I want to quit the using clause and
// go to line marked //x below
// using break or return drop me to line //y
// outside of the for loop.
}
}
} //x
}
//y
我曾尝试使用 break,它在 //y 处将我吐出,但是我想留在 //x 处的 for 循环中,以便 for 循环继续处理。我知道我可以通过抛出异常并使用 catch 来做到这一点,但如果有更优雅的方式来打破使用,我宁愿不做这个相对昂贵的操作。谢谢!