Is there a VB.NET equivalent of C# out parameters?

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

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

Example:

Sub Main()
  Dim y As Integer
  Test(y)
End Sub

Sub Test(ByRef x As Integer)
  x = 42
End Sub

(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.)

Leave a Comment