Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 11 / 68

Sorting an array

This lesson covers sorting an array with VB.NET's Array.Sort, with the aim of understanding an operation used constantly in practice.

Array.Sort() sorts an array, and String.Join() joins its contents into a single string. Sorting comes up constantly in real programs — ranking displays, deciding the order of search results.

The sample code sorts a numeric array into ascending order with Array.Sort(nums) and converts it into readable text with String.Join(", ", nums). Note that Array.Sort() rewrites the original array in place.

A common early stumble is sorting in descending order. Array.Sort() is ascending by default, so descending needs an extra argument. There is also an overload taking a comparison, which lets you define any order you like.

Being able to specify ascending or descending lets you switch the display order to suit. Real applications often let the user choose the sort criterion themselves.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)