ref:
变量需赋值,值带入方法,参与逻辑运算,最终对相应变量赋值;
out:
变量值不带入方法,参与逻辑运算,最终对相应变量赋值;
int.tryparse(string s,out int n) //用out不用ref
示例:
private void RefAndOut(ref int i,out int j) { i++; j++; } int i = 1; int j = 2; RefAndOut(ref i,out j); Console.WriteLine("i="+i); Console.WriteLine("j="+j);
结果:----------------------- i=2; j=1; -----------------------
时间: 2024-10-22 22:49:14