打破尝试 [英] Break out of Try

查看:42
本文介绍了打破尝试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何突破try条款?

在vb.net中,我可以退出试试。我如何在C#中执行此操作?

How can I break out of a try clause?
In vb.net I can do ''Exit try''. How do I do that in C#?

推荐答案



退出尝试转换为C#中的转到/标签。

c#(或vb.net)不推荐转到。


HTH,


Sam

2005年4月4日星期一09:40:46 -0700,Arne

< Ar ** @ discuss.microsoft.com>写道:

Exit Try translates to a goto/label in C#. Goto is not recommended in
c# (or vb.net).

HTH,

Sam
On Mon, 4 Apr 2005 09:40:46 -0700, "Arne"
<Ar**@discussions.microsoft.com> wrote:
如何突破try条款?
在vb.net中,我可以退出试试。我如何在C#中做到这一点?
How can I break out of a try clause?
In vb.net I can do ''Exit try''. How do I do that in C#?




B-Line现在正在招聘一个华盛顿特区的VB.NET

开发者用于WinForms + WebServices位置。

中级到高级开发人员。对于

信息或将电子邮件简历应用于

sam_blinex_com。



B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.


A" try"不是循环。什么都没有打破在......之外。如果你想改变你的代码流量,只需忽略尝试即可。关键字(以及

整个catch块)。例如,如果你认为你想要:


试试

{

///做东西

如果(A == B)

退出试试;

//当A!= B

}时做更多的事情>
catch

{

//日志错误

}

//继续这里

将其形象为

///做东西

if(A == B)

退出试试;

//当A!= B

//继续这里时做更多的事情


应该让答案显而易见:

试试

{

///做东西

if(A!= B)

{

//当A!= B

}时做更多的事情

}

catch

{

//日志错误

}

//继续在这里


Arne <氩** @ discussions.microsoft.com>在留言中写道

新闻:A5 ********************************** @ microsof t.com ...
A "try" is not a loop. There is nothing to "break" out of. If you want
to change the flow of your code, just ignore the "try" keyword (and the
entire catch block). For example, if you think you want:

try
{
/// do stuff
if (A == B)
exit try;
// do more stuff when A!=B
}
catch
{
// log error
}
// continue here
image it as
/// do stuff
if (A == B)
exit try;
// do more stuff when A!=B
// continue here

which should make the answer obvious:
try
{
/// do stuff
if (A != B)
{
// do more stuff when A!=B
}
}
catch
{
// log error
}
// continue here

"Arne" <Ar**@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
如何摆脱try子句?
在vb.net中,我可以退出试试。如何在C#中执行此操作?
How can I break out of a try clause?
In vb.net I can do ''Exit try''. How do I do that in C#?



您是否尝试过break语句?


public static void Main ()

{

尝试{

for(int i = 0; i< 10; i ++){

Console.WriteLine(i.ToString());

if(i == 5)break;

}

}

catch {};


Console.WriteLine(" After the Break Statement");


Console.ReadLine( );

}

Have you tried the break statement?

public static void Main()
{
try{
for(int i=0;i<10;i++){
Console.WriteLine(i.ToString());
if (i == 5) break;
}
}
catch {};

Console.WriteLine("After the Break Statement");

Console.ReadLine();
}


这篇关于打破尝试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆