您的位置:首页 > 其它

ref out

2016-05-18 10:33 316 查看
They're pretty much the same - the only difference is that a variable you pass as an
out
parameter doesn't need to be initialized but passing it as a
ref
parameter it has to be set to something.

int x;
Foo(out x); // OK

int y;
Foo(ref y); // Error: y should be initialized before calling the method

Ref
parameters are for data that might be modified,
out
parameters are for data that's an additional output for the function (eg
int.TryParse
) that are already using the return value for something.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: