如何在发送 ref 参数时 return out 参数?
How to return an out parameter when sending a ref parameter?
我正在发送一个参考参数;想要 return 一个输出参数。除了 ref 方法,我还需要创建另一个方法吗?
这是我正在做的事情的一些背景:"Create an internal static void method that receives degrees Celsius as a ref parameter and returns degrees Fahrenheit as an out parameter. There is no input or output in this method."
internal static void(ref int c, out int f){
f = c + 32;
return f;
}
您的方法有两个问题 - 您缺少方法名称,并且当您的方法签名指定 void
return 类型时,您正在 returning 一个值。
第三件事虽然不是问题,但将 c 声明为 ref 参数没有意义,因为它在您的方法中没有被更改。
internal static void convertCelciusToFahrenheit (ref int c, out int f){
f = c + 32;
}
您可能还想检查一下您的 math to convert celsius to fahrenheit
我正在发送一个参考参数;想要 return 一个输出参数。除了 ref 方法,我还需要创建另一个方法吗?
这是我正在做的事情的一些背景:"Create an internal static void method that receives degrees Celsius as a ref parameter and returns degrees Fahrenheit as an out parameter. There is no input or output in this method."
internal static void(ref int c, out int f){
f = c + 32;
return f;
}
您的方法有两个问题 - 您缺少方法名称,并且当您的方法签名指定 void
return 类型时,您正在 returning 一个值。
第三件事虽然不是问题,但将 c 声明为 ref 参数没有意义,因为它在您的方法中没有被更改。
internal static void convertCelciusToFahrenheit (ref int c, out int f){
f = c + 32;
}
您可能还想检查一下您的 math to convert celsius to fahrenheit