Reputation: 11
In VB .NET, What is the difference between declaring the functions's data type and ignoring it, i mean is it declared as an Object like the Variables or like something else? to be clearer which function of these two is better:
Private Function foo(ByVal text As String)
Return text
End Function
Private Function foo2(ByVal text As String) As String
Return text
End Function
Does the first one declared "As Object"? and if so, that means the second one in better, right?
Upvotes: 1
Views: 674
Reputation: 460228
The second is clearly better, the first exists only for backwards compatibility reasons. It is only allowed with Option Strict
set to Off
which is not recommended anyway.
This is the compiler error you normally get:
Option Strict On requires all Function, Property, and Operator declarations to have an 'As' clause
The return type is Object
for the first.
Upvotes: 3