Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建随机数,将它们存储在数组中,并在两个列表框c中对它们进行排序#_C#_Arrays_Sorting - Fatal编程技术网

C# 创建随机数,将它们存储在数组中,并在两个列表框c中对它们进行排序#

C# 创建随机数,将它们存储在数组中,并在两个列表框c中对它们进行排序#,c#,arrays,sorting,C#,Arrays,Sorting,我试图生成随机的int数字,一旦生成它们,我想将它们存储在列表框中,然后将它们排序到第二个列表框中。我拥有的代码: int Min = 0; int Max = 6; // this declares an integer array with 5 elements // and initializes all of them to their default value // which is zero

我试图生成随机的
int
数字,一旦生成它们,我想将它们存储在
列表框中,然后将它们排序到第二个
列表框中。我拥有的代码:

        int Min = 0;
        int Max = 6;

        // this declares an integer array with 5 elements
        // and initializes all of them to their default value
        // which is zero
        int[] test2 = new int[6];

        Random randNum = new Random();
        for (int i = 1; i < test2.Length; i++)
        {
            test2[i] = randNum.Next(Min, Max);    
        }
        arrayListbox.ItemsSource = test2;
        Array.Sort(test2);
        foreach (int value in test2)
        {
            arrayListboxOrder.ItemsSource = test2;
        }
intmin=0;
int Max=6;
//这声明了一个包含5个元素的整数数组
//并将它们全部初始化为其默认值
//哪个是零
int[]test2=新的int[6];
Random randNum=新的Random();
for(int i=1;i
项目资源需要是不同的数组,否则它们基本上具有相同的数据。把一个排序,把它们都排序

尝试:

我在这里保存了一个片段:

好的,那么出了什么问题,您遇到了什么问题?而“完全冗余和不必要的注释奖励”的奖励是:“这声明了一个包含5个元素的整数数组,并将所有元素初始化为其默认值,即零”。另外,它也错了:它有6个元素,而不是5个。我注意到注释也错了…我有两个相同内容的列表,我的目的是有两个不同的列表,一个是随机数(未排序),另一个是随机数(排序),这是一个很好的例子,说明为什么你从不使用这样的注释
arrayListbox.ItemsSource = test2;
int[] sorted = (int[])test2.Clone();
Array.Sort(sorted);
arrayListboxOrder.ItemsSource = sorted;
        int Min = 0;
        int Max = 6;
        // this declares an integer array with 5 elements
        // and initializes all of them to their default value
        // which is zero
        //int[] test2 = new int[6];

        arrayListboxOrder.ItemsSource = Enumerable.Range(Min, Max).OrderBy(x => Guid.NewGuid()).Take(5).OrderBy(n=>n).ToArray();