Out and ref difference notes in C # in the pass parameter

Source: Internet
Author: User

//out parameters need to be assigned before the parameter is passed, ref is not required.
Both out and ref parameters can change values
1 Static voidMain (string[] args)2 {3 intI =Ten;4 //int J = ten;5 //int I;6 intJ;7 //int[] K=new int[5]{1,2,3,4,5};8 int[] k =New int[5];9 //int[] L = new int[5]{1,2,3,4,5};Ten int[] L =New int[5]; One ATestClass1 TC =NewTestClass1 (); -Tc.testclass (refI); -Tc.testclass1 ( outJ); the -Tc.testclass2 ( outk); -TC.TESTCLASS3 (refl); - +Console.WriteLine ("Out I:"+I); -Console.WriteLine ("ref J:"+J); + AConsole.WriteLine ("Out k[0]:"+ k[0]); atConsole.WriteLine ("ref l[0]:"+ l[0]); - Console.read (); - } - Public voidTestClass (ref inti) - { -i = -; in } - Public voidTestClass1 ( out inti) to { +i = -; - } the Public voidTestClass2 ( out int[] k) * { $k=New int[5];Panax Notoginsengk[0] = -; - } the Public voidTESTCLASS3 (ref int[] l) + { AL =New int[5]; thel[0] = -; + } - $ $}

Out and ref difference notes in C # in the pass parameter

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.