您当前的位置: 首页 >  c#

C# 参数关键字out

发布时间:2013-01-29 13:44:34 ,浏览量:0

out关键字会导致参数通过引用来传递,这与ref关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化

当希望方法返回多个值时,声明out方法很有用,示例如下:

int i ; string str1, str2; UseOut(out i,out str1,out str2); // i is now 44 // str1 is now "字符串1" // str2 is (still) null; public static void UseOut(out int i,out string str1,out string str2) { i = 44; str1 = "字符串1"; str2 = null; }

注意:

1.使用out参数,方法定义和方法使用都必须显示使用out关键字

2.尽管作为 out 参数传递的变量不必在传递之前进行初始化,但需要调用方法以便在方法返回之前赋值。

3.属性不是变量,因此不能作为 out 参数传递

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    105940博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0687s