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

Transforming an array (map)

This lesson covers transforming an array with VB.NET's Array.ConvertAll, with the aim of processing every element in one go.

Array.ConvertAll(array, Function(element) newValue) builds a new array by applying the same operation to each element. It states the intent more clearly and concisely than a For loop.

The sample code builds doubled by doubling each element of the original {1, 2, 3} with Array.ConvertAll(nums, Function(n) n * 2). The Function(n) n * 2 form is an anonymous function (a lambda) defined on the spot.

A common early stumble is that Array.ConvertAll returns a new array rather than changing the original. nums itself is unchanged, so you have to receive the return value to use the result.

In professional work, this shape comes up whenever data is transformed in bulk — applying tax to prices, converting units.

๐Ÿ“– 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)