开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜