Open
Description
Since VB 9, using ByVal
is no longer mandatory, making method declaration syntax quite a bit cleaner. For ByRef
, a keyword is still required, and unlike with C#, VB doesn't have an out-specific keyword. Instead, you need to use both ByRef
and apply the OutAttribute
, for example:
Private Function TryGetValue(obj As Object, <Out> ByRef result as Integer) As Boolean
End Function
This makes it easy to introduce a bug* that doesn't become apparent until runtime:
Private Function TryGetValue(obj As Object, <Out> result as Integer) As Boolean
End Function
This code looks fine at first glance, But the <Out>
attribute doesn't actually do anything meaningful (best as I can tell), because result
is actually implicitly ByVal
now, not ByRef
.
Thus, I propose that the compiler annotate this as a warning:
OutAttribute
used onByVal
method parameter. Consider usingByRef
.
*) Well, this has embarrassingly happened to me, anyway.