gpt4 book ai didi

c#-4.0 - C# 4.0 可选 out/ref 参数

转载 作者:行者123 更新时间:2023-12-03 04:10:21 26 4
gpt4 key购买 nike

C# 4.0 是否允许可选的 outref 参数?

最佳答案

没有。

解决方法是使用另一个没有 out/ref 参数的方法进行重载,该方法仅调用当前方法。

public bool SomeMethod(out string input)
{
...
}

// new overload
public bool SomeMethod()
{
string temp;
return SomeMethod(out temp);
}
<小时/>

如果您有C# 7.0 ,您可以简化:

// new overload
public bool SomeMethod()
{
return SomeMethod(out _); // declare out as an inline discard variable
}

(感谢@Oskar/@Reiner 指出了这一点。)

关于c#-4.0 - C# 4.0 可选 out/ref 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2870544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com