C#6有一个名为"异常过滤"的新功能
语法是这样的:
catch (Win32Exception exception) when (exception.NativeErrorCode == 0x00042)
{
//Do something here
}
Run Code Online (Sandbox Code Playgroud)
我不禁想知道当前的方法有什么好处:
catch (Win32Exception exception)
{
if (exception.NativeErrorCode == 0x00042)
{
//Do something here
}
}
Run Code Online (Sandbox Code Playgroud)
在大括号之前进行过滤是一件大事吗?也许与性能或安全性有关?