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)