1,随机输出数组中所有的值(不重复)

static void Main(string[] args)
        {
            int[] array = { 1, 2, 3, 4, 5 };
          int[]str=new int[array.Length];
          Random r = new Random();
          for (int i = 0; i < array.Length; i++)
          {
              int index = r.Next(array.Length);
              //判断是否已经包含
              if (str.Contains(array[index]))
              {
                  i--;
                  continue;
              }
              str[i] = array[index];
              //数组中直接输出,就可以不用下面的for循环
              //Console.WriteLine(str[i]);
          }
          for (int j = 0; j < str.Length; j++)
          {
              Console.WriteLine(str[j]);
          }
          Console.ReadKey();
View Code

相关文章:

  • 2021-07-04
  • 2022-12-23
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-16
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2021-06-23
相关资源
相似解决方案