转换一些 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/