[英]What is the name of this technique of returning multiple values from a function in vb.net?
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.
您可以返回 class 或结构,而 class 或结构可以包含多个值。
However, recent vb.net improvement allow a convenient way to allow an anonymous type as return values.然而,最近的 vb.net 改进提供了一种方便的方法来允许匿名类型作为返回值。
However, I cannot find any reference to that method anywhere on the.net.但是,我在 .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.那么它在哪里,我应该在谷歌搜索什么来了解更多关于这个功能的信息。
It's Tuples introduced in Visual Basic 15 / Visual Studio 2017 .它是Visual Basic 15 / Visual Studio 2017中引入的元组。
See the section: Tuples as method return values where it mentions (with code examples):请参阅部分: Tuples as method return values其中提到(带有代码示例):
A method can return only a single value.
一个方法只能返回一个值。 Frequently, though, you'd like a method call to return multiple values.
但是,您经常希望方法调用返回多个值。 There are several ways to work around this limitation:
有几种方法可以解决此限制:
You can create a custom class or structure whose properties or fields represent values returned by the method.
您可以创建自定义 class 或结构,其属性或字段表示该方法返回的值。 This is a heavyweight solution;
这是一个重量级的解决方案; it requires that you define a custom type whose only purpose is to retrieve values from a method call.
它要求您定义一个自定义类型,其唯一目的是从方法调用中检索值。
You can return a single value from the method, and return the remaining values by passing them by reference to the method.
您可以从该方法返回单个值,并通过引用传递给该方法来返回其余值。 This involves the overhead of instantiating a variable and risks inadvertently overwriting the value of the variable that you pass by reference.
这涉及实例化变量的开销,并且有无意中覆盖通过引用传递的变量值的风险。
You can use a tuple , which provides a lightweight solution to retrieving multiple return values .
您可以使用元组,它提供了一种轻量级的解决方案来检索多个返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.