Creating random Numbers, store them in array and sort them in two listboxes c# -
i trying generate random int
numbers, once generate them want store them in listbox
, after sort them in second listbox
. code have:
int min = 0; int max = 6; // declares integer array 5 elements // , initializes of them default value // 0 int[] test2 = new int[6]; random randnum = new random(); (int = 1; < test2.length; i++) { test2[i] = randnum.next(min, max); } arraylistbox.itemssource = test2; array.sort(test2); foreach (int value in test2) { arraylistboxorder.itemssource = test2; }
the itemssource
needs different array - otherwise both fundamentally have same data. sort one, sort them "both".
try:
arraylistbox.itemssource = test2; int[] sorted = (int[])test2.clone(); array.sort(sorted); arraylistboxorder.itemssource = sorted;
Comments
Post a Comment