Yahtzee Variables - Create Sorted Array
In a Yahtzee project, I have 5 integer vairabls n1, n2, n3, n4 and n5. I need a function that creates and uses a sorted integer array i(0 to 5) from the variables listed above. The 5 variables are form-level variables. The array will only be used in the function.
I know there's Dim i as arraylist and there's i().sort. I'm just not sure how to use them.
Re: Yahtzee Variables - Create Sorted Array
Just put them in an array and call the Array.Sort(). By default, the Sort method orders numbers from lowest to highest, so you don't need to do anything special with it.
In your function:
vb Code:
Dim i As Integer() = New Integer() {n1, n2, n3, n4, n5}
Array.Sort(i)
Re: Yahtzee Variables - Create Sorted Array
VB.Net Code:
Dim intArray() As Integer = {n1, n2, n3, n4, n5}
Array.Sort(intArray)
Edit: dang it :)
Re: Yahtzee Variables - Create Sorted Array
See, by only typing "i" instead of "intArray", I got my answer in first. :)
Re: Yahtzee Variables - Create Sorted Array
That's certainly easier than the nested loop/ bubble sort stuff I was doing.