<分区>
给定初始代码:
callSomeFunction(someParameter);
目前函数有返回值,但没有使用到值。但是,我们需要提供一个跟踪日志,所以我们修改代码如下:
#if DEBUG
Debug.Print $"Entering function with {nameof(someParameter)}: {someParameter}";
#endif
var result = callSomeFunction(someParameter);
#if DEBUG
Debug.Print $"Leaving function with result: {result}";
#endif
在发布版本中,代码基本上等同于:
var result = callSomeFunction(someParameter);
显然 result
没有被使用。那么随着这些变化,是否有任何性能影响只是因为它现在正在获取最初没有的返回值?不只制作 2 个不同 block 的最初原因是,做后者可能容易出错,因为现在有 2 个调用站点需要维护,而上面的版本只保留 1 个调用站点需要维护。