我有以下两个函数,那几乎是一样的,唯一的区别就是一个使用func
,其他的action
。如果可能的话,我想将它们合并成一个函数。C#用void写回函数的方法返回
private static void TryCatch(Action action)
{
try
{
action();
}
catch (Exception x)
{
Emailer.LogError(x);
throw;
}
}
private static TResult TryCatch<TResult>(Func<TResult> func)
{
try
{
return func();
}
catch (Exception x)
{
Emailer.LogError(x);
throw;
}
}
感谢为什么这是不可能的解释。 – CaffGeek