浏览网络以在 C# 中更好地处理故障,我已经了解了以下实现策略。第一个对我来说很自然,而另一个实现我不确定它的优点是什么?
1)
static void Fault(Action protectedBlock, Action faultHandler)
{
try
{
protectedBlock();
}
catch
{
faultHandler();
throw;
}
}
2)
static Action Fault(Action protectedBlock, Action faultHandler)
{
return () =>
{
try
{
protectedBlock();
}
catch
{
faultHandler();
throw;
}
};
}
2) 是在 C# 中开发高阶函数时的首选策略吗?
而且,我想知道,如果一种方法比另一种更有效。