C#相当于VB.NET的Catch ... When [英] C# equivalent to VB.NET's Catch...When
本文介绍了C#相当于VB.NET的Catch ... When的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VB.NET中,我经常 Catch ...当
:
In VB.NET I often Catch…When
:
Try
…
Catch e As ArgumentNullException When e.ParamName.ToUpper() = "SAMPLES"
…
End Try
是否有相当于的C#Catch ...当
?
如果可能,我不想诉诸使用,如果
p> catch
中的
I don't want to resort to using an if
statement inside a catch
if possible.
推荐答案
此功能已被C#6公布。现在可以写
This functionality was announced for C# 6. It is now possible to write
try { … }
catch (MyException e) when (myfilter(e))
{
…
}
您可以下载 Visual Studio 2015 现在检查一下,或者等待官方发布。
You can download the preview of Visual Studio 2015 now to check this out, or wait for the official release.
这篇关于C#相当于VB.NET的Catch ... When的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文