微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在VB.NET中声明嵌套函数?

我如何在VB.NET中声明嵌套函数?例如,我想做这样的事情:

Function one()
    Function two()
    End Function
End Function

但是,由于未封闭的功能,此声明在VB.NET中无效.

解决方法

你在问如何写一个 lambda expression吗?

A lambda expression is a function or subroutine without a name that can be used wherever a delegate is valid. Lambda expressions can be functions or subroutines and can be single-line or multi-line. You can pass values from the current scope to a lambda expression.

You create lambda expressions by using the Function or Sub keyword,just as you create a standard function or subroutine. However,lambda expressions are included in a statement.

例如,以下代码将打印“Hello World!”:

Dim outputString As Action(Of String) = Sub(x As String)
                                            Console.WriteLine(x)
                                        End Sub
outputString("Hello World!")

有关更多示例,请参见此处:VB.NET Lambda Expression

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐