C # function parameter transfer-out and ref applications

Source: Internet
Author: User
1. Similarities Between out and ref reference parameters: both pass parameters to the function through reference.

2.The difference between the out parameter and the ref parameter is that the parameter is passed through the ref reference. The parameter must be initialized and cannot be initialized in the function that calls it.

3.Multiple parameters are referenced by the out clause to return multiple values. This allows the method to return the required values at will.

4.If one method uses ref to reference a parameter and the other method uses out to reference the parameter, the functions with the same method name cannot be overloaded; otherwise, a compilation error occurs.

"Cannot define overloaded methods that differ only on ref and out"

5.The ref parameter is used to change the reference type, because the reference type is passed as the ref parameter and the object will be changed.

6.You can use ref and out to pass the array. When using ref to pass the array, you must Initialize an array in the main function.

You can specify an array as a null value or initialize it into a different array.

To assign a value to an array.

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.