基础学习第三天

将数组中的内容反转:

                          eg:string []country={"中国","美国","巴西","澳大利亚","加拿大"};

                               Inversion(country);


                              public static void Inversion(string []country)

                              {

                           //交换数组前后两个元素   两两进行比较 所以只需要比较(长度/2)次

                                            for(int i=0;i                                             {

                                                      //交换元素

                                                    //将数组中最后一个元素放进临时变量中

                                                    int temp=country[country.Length-1-i]  ;

                                                   country[country.Length-1-i]= country[i];

                                                    country[i]=temp;

                                            }

                                          //遍历数组

                                          foreach(string word in country)

                                          {

                                                     Console.WriteLine(word);

                                         }

                               }

你可能感兴趣的:(基础学习第三天)