[C#] C#中数组反转和排序演示代码 →→→→→进入此内容的聊天室

来自 , 2020-11-03, 写在 C#, 查看 147 次.
URL http://www.code666.cn/view/daad8d50
  1. using System;
  2.  
  3. public class ArraySample
  4. {
  5.     public static void Main()
  6.     {
  7.  
  8.         // Create and initialize a new array instance.
  9.         Array strArr = Array.CreateInstance(typeof(string), 3);
  10.         strArr.SetValue("Mahesh", 0);
  11.         strArr.SetValue("chand", 1);
  12.         strArr.SetValue("Test Array", 2);
  13.  
  14.         // Display the values of the array.
  15.         Console.WriteLine("Initial Array values:");
  16.         for (int i = strArr.GetLowerBound(0);
  17. i <= strArr.GetUpperBound(0); i++)
  18.             Console.WriteLine(strArr.GetValue(i));
  19.  
  20.         //sort the value of the array.
  21.         Array.Sort(strArr);
  22.  
  23.         Console.WriteLine("After sorting:");
  24.         for (int i = strArr.GetLowerBound(0);
  25. i <= strArr.GetUpperBound(0); i++)
  26.             Console.WriteLine(strArr.GetValue(i));
  27.  
  28.         // Reverse values of the array.
  29.         Array.Reverse(strArr);
  30.  
  31.         for (int i = strArr.GetLowerBound(0); i <= strArr.GetUpperBound(0); i++)
  32.             Console.WriteLine(strArr.GetValue(i));
  33.  
  34.     }
  35. }
  36. //csharp/7522

回复 "C#中数组反转和排序演示代码"

这儿你可以回复上面这条便签

captcha