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

Returning several values from a function (tuples)

This lesson covers returning several values from one function with a tuple in VB.NET, with the aim of writing functions not limited to a single return value.

A tuple lets a function return several values as one bundle. It is a light-touch way to hand back related results together, such as a minimum and a maximum, without defining a new class.

The sample code declares the return type as Function MinMax(...) As (Min As Integer, Max As Integer) and returns both with Return (nums.Min(), nums.Max()). The caller reaches each value by name, as result.Min and result.Max.

A common early stumble is leaving the tuple elements unnamed, which makes it hard to tell which value is which. Naming them (Min As Integer, Max As Integer) as in the sample makes the code far more readable.

In professional work, tuples are used to return several related values together — a success flag alongside a result message, for instance.

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