Home > Mobile >  What is the name of this technique of returning multiple values from a function in vb.net?
What is the name of this technique of returning multiple values from a function in vb.net?

Time:11-28

Protected Function ammountChanges(order As BasicSimpleOrder, createOrDelete As Boolean) As (change As Decimal, currency As String)


End Function

I sort of know that it's possible and I want to learn more about it.

However, if I search in google for

function returning multiple values vb.net

for example,

or in stackoverflow

no body is mentioning that technique.

Even if I search for

function returning multiple values through anonymous type 

people are still using different techniques.

Now I think it's a new feature.

Basically, you "can't" really return multiple values. You can return a class or a struct and that class or struct can contain multiple values.

However, recent vb.net improvement allow a convenient way to allow an anonymous type as return values.

However, I cannot find any reference to that method anywhere on the net. Not easily. Not with the keyword I found.

So where is it, and what should I search in google to learn more about this feature.

CodePudding user response:

Posting as an answer, as suggested by @VC.One

It's Tuples introduced in Visual Basic 15 / Visual Studio 2017.

Recommended reading by @VC.One: Tuples as method return values

CodePudding user response:

You could create a custom class that has the values that you want to return in it. Then make the custom class the return type for your function, like this:

Protected Function ammountChanges(order As BasicSimpleOrder, createOrDelete As Boolean) As CustomReturnType

End Function

Public Class CustomReturnType
      Public change As Decimal
      Public currency As String
End Class
  • Related