Is there a difference between Return and func()=
Is there any difference between the following:
public function returnString() as string
return "string"
end fun开发者_运维百科ction
and
public function returnString() as string
returnString = "string"
end function
No there isn't any difference in terms of emitted IL. In this specific case the same gets baked into the resulting assembly. The first looks more C-sharpish while the second is more VB-ish. It's a matter of a personal VB.NET coding style preference.
This being said there is a crucial difference: the Return statement returns the control immediately whereas in the second case allows for any lines following the assignment to be executed.
And my .2¢ on the matter: always use the Return
statement.
精彩评论