我正在尝试退出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
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用break来解决这个问题,但是我希望保持在// x的for循环中,以便for循环继续处理.我知道我可以通过抛出异常并使用catch来实现它,但是如果有一种更优雅的方法来突破使用,我宁愿不做这个相对昂贵的操作.谢谢!
c# ×1