C#中的VB.NET语法对应项. [英] VB.NET syntax counterpart in C#.

查看:76
本文介绍了C#中的VB.NET语法对应项.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下与c#中的语句相对应的是什么?

What''s the counterpart of the following statement in c#?

Try

Catch sqlex As SqlException When sqlex.Number = 547

End Try

推荐答案

在这里是:

Here it is:

try{
// Some code here
}
catch(SqlException sqlException){
if( sqlException.Number == 547){
// Do something
)
else{
// Do something
}
}



如果要跟踪大量数字,请使用switch.



If you are tracking a lot of numbers, then use switch.


try {
}
catch (SqlException sqlex) {
    sqlex.Number = 547;
}



要避免所有进一步的混乱, 这个想法是,程序控件仅在异常号为547时才进入catch块. .我在 C# 中找不到 When 关键字的任何对应项.这就是我发布的原因.无论如何,感谢大家的简短而有益的讨论.问候.
To be clear from all further confusions, the idea is the program control will only enter the catch block if the exception number is 547. I was unable to find any counterpart of the When keyword in C#. That''s why I posted for. Anyway thanks everyone for the short but informative discussion. Regards.


这篇关于C#中的VB.NET语法对应项.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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