小编baz*_*own的帖子

反转数组中的元素

我设置了一个数组,我想创建一个方法,返回一个反向元素的数组.例如,如果有10个槽,那么array1[9] = 6那么array2[0] = 6.
我想我必须返回一个数组 - 我该怎么做?
而且我不知道如何反转并添加到另一个数组.
谢谢!

        int[] arr = {43, 22, 1, 44, 90, 38, 55, 32, 31, 9};
        Console.WriteLine("Before");
        PrintArray(arr);
        Console.WriteLine("After");
        Reverse(arr);

         Console.ReadKey(true);

    }

    static int[] Reverse(int[] array)
    {
        for (int i = array.Length; i < 1; i--)
        {
            int x = 0;

            array[i] = array[x++];
            Console.WriteLine(array[i]);
        }

       }


         static void PrintArray(int[] array)
    {
        for (int j = 0; j < array.Length; j++)
        {
            Console.Write(array[j] + " ");

        }
        Console.WriteLine("");
Run Code Online (Sandbox Code Playgroud)

c# arrays reverse

3
推荐指数
3
解决办法
2万
查看次数

C#找到数组中最短和最长的单词

我试图找到基于长度的最短和最长的字符串值,并且我卡住了.截至目前,脚本在写字线后退出.我认为代码需要一些帮助,我不认为for循环可以自己工作.任何援助将不胜感激.

        for (int i = 5; i <0; i++)
        {
            string[] word = new string[5];
           Console.WriteLine("Type in a word");
            word[i] = Console.ReadLine();

             int length = word[i].Length;
             int min = word[0].Length;
             int max = word[0].Length;
             string maxx;
             string minn;


              if (length > max)
                 {
                   maxx = word[i];
                   Console.Write("Shortest");
                  }
             if (length < min) 
              {
                 minn = word[i];
                Console.Write("Longest");
              }



         }
        Console.ReadKey(true);
    }
Run Code Online (Sandbox Code Playgroud)

c# arrays shortest

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

arrays ×2

c# ×2

reverse ×1

shortest ×1