6 c# parameters methods parameter-passing
就像是:
如果在呼叫使用之前不需要实例化
如果变量的值用于返回,则决定或计算方法调用中的其他值不要使用ref也不要
我弄错了吗?你的简短指南是什么?
不确定这是否真的回答了您的问题,但我发现通过 ref (使用 out 关键字)传递值的一个很好的用法是......
int i = 0;
if (int.TryParse("StringRepresentation", out i)
{
// do something with i which has taken the value of a the previous successful TryParse
}
Run Code Online (Sandbox Code Playgroud)