Unity C # ref and out

Source: Internet
Author: User

Both ref and out are passed by address and will change the original value after use. The ref method parameter keyword enables a method reference to be passed to the same variable of the method. When control is passed back to the calling method, any changes made to the parameter in the method are reflected in the variable. To use the ref parameter, you must explicitly pass the parameter to the method as a ref parameter. The value of the ref parameter is passed to the ref parameter. The arguments passed to the ref parameter must be initialized first. property is not a variable and cannot be passed as a ref parameter.

The Out method parameter keyword on the method parameter causes the method reference to be passed to the same variable of the method. When control is passed back to the calling method, any changes made to the parameter in the method are reflected in the variable. Declaring an out method is useful when you want a method to return more than one value. Methods that use out parameters can still return a value. A method can have more than one out parameter. To use an out parameter, you must explicitly pass the parameter to the method as an out parameter. The value of the out parameter is not passed to the out parameter (that is, out only does not go out). You do not have to initialize a variable passed as an out parameter. However, you must assign a value to the out parameter before the method returns. property is not a variable and cannot be passed as an out parameter. Ref can pass the value of a parameter into a function, but out is to empty the parameter, that is, you cannot pass a value out of the out, and after it is out, the value of the parameter is empty, so you must initialize it once.

These are all nonsense.

Two differences: REF is there in and out and out is only out of the go.

The ref and out keywords are handled differently at run time, but are handled the same way at compile time. Therefore, if one method takes a ref parameter and the other method takes an out parameter, the two methods cannot be overloaded.

Unity C # ref and out

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.