c# - VB.NET 函数没有返回值,转换为 C# 会返回错误?

标签 c# .net vb.net translate

转换一些 VB.NET 代码。某些静态函数对通过引用传递的某些参数进行一些处理,但不返回任何内容。 VB.NET 函数到底发生了什么,它们可以在没有返回值的情况下存在,并且不会出现任何调试错误? bool 值会发生什么?

Overloads Shared Function ExampleMethod(ByRef buffer1() as Byte, ByRef buffer2() as Byte) As Boolean
'do stuff here, no return types
End Function

Overloads Shared Function ExampleMethod(ByRef buffer1() as Byte, ByRef buffer2 as Byte) As Boolean
'do stuff here, no return types
End Function

最佳答案

参见https://msdn.microsoft.com/en-us/library/sect4ck6.aspx

使用 VB.Net,您可以通过使用 Return 语句返回一个值,或者为函数名称分配一个值,例如:

    ExampleMethod = true
    Exit Function
End Function

它接着说:

If you use Exit Function without assigning a value to name, the procedure returns the default value for the data type that's specified in returntype. If returntype isn't specified, the procedure returns Nothing, which is the default value for Object.

C# 更严格一些!

关于c# - VB.NET 函数没有返回值,转换为 C# 会返回错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39442461/

相关文章:

c# - Entity Framework 5 代码优先的键命名

c# - 刷新强类型数据集

c# - 通过 TCP 处理客户端/服务器通信 - 一般问题

.net - 如何在 Linq to Sql 中使用单个查询插入/更新/删除多个对象

vb.net - 在vb.net服务应用程序中使用ffmpeg

c# - 在我的 C# 应用程序中结合使用 Task 和 IObservable 是一种不好的做法吗?

c# - 当 DataTemplate 具有可见性绑定(bind)时,WPF ListBox 自动宽度更改不正确

c# - 对通过 XmlWriter 输出的函数进行单元测试?

vb.net - 慢 Paypal NVP API

c# - 控制音量混合器