其实这两关键字也不过是对其的简单化 我们先看下用java写的
static void Main(string
[] args
)
{
int reffs
= setjava(1000);
Console
.WriteLine(reffs
);
}
public static int setjava(int a
)
{
return 30;
}
这样实现起来是不是很麻烦呢
因此C#对此方法进行了简化
static void Main(string[] args
)
{
int reff
= 100;
set(ref reff
);
Console
.WriteLine(reff
);
}
public static void set(ref int a
)
{
a
= 10;
}
神奇不,其实就是对形参直接进行的修改
你若问我
out和
ref有什么区别,我也不知道,我感觉其实可以混用,
out用于输出,
ref用于修改
转载请注明原文地址:https://blackberry.8miu.com/read-15443.html