Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15621

Arrays- Sorting and initialization

$
0
0
Howdy people,

.Net Arrays are slightly confusing to me and these two issues came up.

1) I have a 2 dimensional array of integers representing 2D coordinates (X,Y) what would be the best way to sort it by ascending Y value considering I need the corresponding X values of the Y to follow.
Maybe splitting it into two arrays to use the array.sort() function ?

vb.net Code:
  1. Dim arr_Points As Integer(,)

2) Initialization of an empty array causes issues (=Nothing) when used further in the code.
I made a messy workaround but I'm hoping someone could suggest me a better alternative.

vb.net Code:
  1. Dim arr_Points As Point()
  2.  
  3. If arr_Points IsNot Nothing Then
  4.     Dim TmP As Point() = arr_Points
  5.     ReDim arr_Points(TmP.Length)
  6.     TmP.CopyTo(arr_Points, 0)
  7.     arr_Points(TmP.Length) = New Point(X_Value, Y)
  8. Else
  9.     ReDim arr_Points(0)
  10.     arr_Points(0) = New Point(X_Value, Y)
  11. End If

Viewing all articles
Browse latest Browse all 15621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>