Some unexpected cases when an array is used as a method parameter

Source: Internet
Author: User

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

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.