objects and types (arrays, ref, out)

Source: Internet
Author: User

1 class Program2     {3         //array is a reference type4         //If you pass other reference types, such as arrays or classes, to a method, the corresponding method uses that reference type to adapt the values in the array .5         //and the new value is reflected on the original array6         Static voidSomeFunction (int[] INTs,inti)7         {8ints[0]= -;9i =Ten;Ten         } One  A         //ref parameter; The method will affect the numeric change of the corresponding parameter by using the parameter of the keyword -         //and the ref parameter needs to be initialized -         Static voidSomeFunction1 (ref intj) the         { -j = -; -         } -  +         //out parameter, out parameter can not be initialized -         //This parameter is passed by reference, and the method returns W to preserve the change to the W value. +         Static voidSomeFunction2 ( out intW) A         { atW = -; -         } -  -         Static voidMain (string[] args) -         { -             #regionSomeFunction in  -             int[] INTs = {1,2,3,4 }; to             inti =1; +  - SomeFunction (INTs, i); the  *Console.WriteLine (ints[0]); $ Console.WriteLine (i);Panax Notoginseng  -  the             //output Result: 100,1 +             //where I is not a change. A  the             #endregion +  -             #regionSomeFunction1 $  $             intj =1;//correct -             //Int J;//Error -  theSomeFunction1 (refj); - Wuyi Console.WriteLine (j); the  -             //Output Result: Wu             //The value of J has changed -  About             #endregion $  -             #regionSomeFunction2 -  -             intW//correct A             //int w = 1;//correct +              theSomeFunction2 ( outW); -  $ Console.WriteLine (w); the  the             //Output Result: the             //the value of W has changed the              -             #endregion in         } the}
View Code

objects and types (arrays, ref, 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.