什么是“裁判”和“出”的关键字之间的区别? [英] What's the difference between the 'ref' and 'out' keywords?

查看:140
本文介绍了什么是“裁判”和“出”的关键字之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个功能,我需要传递一个对象,以便它可以通过函数修改。是什么区别:

I'm creating a function where I need to pass an object so that it can be modified by the function. What is the difference between:

public void myFunction(ref MyClass someClass)

public void myFunction(out MyClass someClass)

我应该使用,为什么?

Which should I use and why?

推荐答案

REF 告诉对象进入此功能之前进行初始化,编译器,而退出告诉对象将在函数内部进行初始化的编译器。

ref tells the compiler that the object is initialized before entering the function, while out tells the compiler that the object will be initialized inside the function.

因此​​,虽然 REF 是两个方面,退出不在只。

So while ref is two-ways, out is out-only.

这篇关于什么是“裁判”和“出”的关键字之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆