Ref keyword usage, ref keyword usage

Source: Internet
Author: User

Ref keyword usage, ref keyword usage

RefThe keyword is used to pass parameters by reference (rather than value.

The effect passed by reference is that any changes made to the parameters in the called method are reflected in the call method.

For example, if the caller passes a local variable expression or an array element access expression, the called method replaces the object with the object referenced by the ref parameter, then, the caller's local variables or array elements start to reference the new object.

To useRefParameters, method definitions, and call methods must be explicitly usedRefKeyword, as shown in the following example.

PassRefParameters must be initialized before being passed.

This correspondsOutThe parameters are different. You do not need to initialize the parameters explicitly before passing them. For more information, see out.

The class member cannot haveRefAndOutDifferent signatures.

If the only difference between two types of members is that one of them hasRefParameter, while the other hasOutParameter, a compilation error occurs.

Related Article

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.