Some unexpected cases when an array is used as a method parameter
Today, when you brush a question, using an array as the parameter of the method, there are some unexpected situations.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceMyArray7 {8 class Program9 {Ten Static voidMain (string[] args) One { A int[] Nums = {1,2,4,5,3,2,5,6,3 }; -Console.WriteLine ("Array Numbers:"); - foreach(intNuminchnums) theConsole.Write (num +" "); - - Sort (nums); -Console.WriteLine ("\nafter Sort:"); + foreach(intNuminchnums) -Console.Write (num +" "); + A Reverse (nums); atConsole.WriteLine ("\nafter Reverse:"); - foreach(intNuminchnums) -Console.Write (num +" "); - - Change (nums); -Console.WriteLine ("\nafter Change:"); in foreach(intNuminchnums) -Console.Write (num +" "); to + Sortandchange (nums); -Console.WriteLine ("\nafter Sortandchange:"); the foreach(intNuminchnums) *Console.Write (num +" "); $ Panax Notoginseng Distinctandchange (nums); -Console.WriteLine ("\nafter Distinctandchange:"); the foreach(intNuminchnums) +Console.Write (num +" "); A the Console.read (); + } - $ Static voidSort (int[] nums) $ { -Nums = ( fromLinchNums byLSelectl). ToArray (); - } the - Static voidReverse (int[] nums)Wuyi { theNums =Nums. Reverse (). ToArray (); - } Wu - Static voidChange (int[] nums) About { $ for(inti =0; I < Nums. Length-1; i++) -Nums[i] = nums[i +1]; - } - A Static voidSortandchange (int[] nums) + { theNums = ( fromLinchNums byLSelectl). ToArray (); - for(inti =0; I < Nums. Length-1; i++) $Nums[i] = nums[i +1]; the } the the Static voidDistinctandchange (int[] nums) the { - int[] result =Nums. Distinct (). ToArray (); in for(inti =0; I < Nums. Length-1; i++) theNums[i] = nums[i +1]; the } About } the}
View Code
Results:
Some unexpected cases when an array is used as a method parameter