VB.NET是否有C#out参数的等效项?

编程入门 行业动态 更新时间:2024-10-28 20:26:41
本文介绍了VB.NET是否有C#out参数的等效项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

VB.NET是否直接等效于C# out 函数参数,其中传递给函数的变量不需要初始化?

Does VB.NET have a direct equivalent to C# out function parameters, where the variable passed into a function does not need to be initialised?

推荐答案

不,在VB中没有 out 关键字。

No, there is no equivalent of the out keyword in VB.

但是,VB会自动初始化方法中的所有局部变量,因此您可以使用 ByRef 而不需要先显式初始化变量。

However, VB does automatically initialise all local variables in a method, so you can use ByRef without needing to explicitly initialise the variable first.

示例:

Sub Main() Dim y As Integer Test(y) End Sub Sub Test(ByRef x As Integer) x = 42 End Sub

(如果您检查框架中的代码(例如 Double.TryParse ),您可能会看到< OutAttribute> 已添加到参数中,但这仅在将调用编组以进行COM互操作或平台调用时有所不同。)

(If you examine code in the framework (for example Double.TryParse), you may see the <OutAttribute> added to parameters, but that only makes a difference when the call is marshalled for COM interop or platform invoke.)

更多推荐

VB.NET是否有C#out参数的等效项?

本文发布于:2023-11-10 18:51:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   VB   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!