开发者

Is there a difference between Return and func()=

开发者 https://www.devze.com 2023-03-01 09:22 出处:网络
Is there any difference between the following: public function returnString() as string return \"string\"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消