有没有一种方法可以让一个函数使用它的可选参数值?例如,假设我有以下代码:
public void myFunction(bool required, string optional = "This is optional") {...}
我希望能做类似以下这样的事情:
string possiblyNull = null; // the result of another function
myFunction(true, possiblyNull ?? possiblyNull : optional)
if...else
包围调用。 - Daniel A. Whiteif (possiblyNull == null) myFunction(true); else myFunction(true, possiblyNull);
。 - Heinzi