For future readers, VB.NET 2017 and above now supports tuples of values as a language function. You declare your function as follows:
Function ColorToHSV(clr As System.Drawing.Color) As (hue As Double, saturation As Double, value As Double) Dim max As Integer = Math.Max(clr.R, Math.Max(clr.G, clr.B)) Dim min As Integer = Math.Min(clr.R, Math.Min(clr.G, clr.B)) Dim h = clr.GetHue() Dim s = If((max = 0), 0, 1.0 - (1.0 * min / max)) Dim v = max / 255.0 Return (h, s, v) End Function
And you call it that:
Dim MyHSVColor = ColorToHSV(clr) MsgBox(MyHSVColor.hue)
Notice how VB.NET creates an open property with the name hue inferred from the return type of the called function. Intellisense also works correctly for these contributors.
However, note that you need to target the .NET Framework 4.7 for this to work. Alternatively, you can install System.ValueTuple (available as a NuGet package) in your project to take advantage of this feature.
source share