No warning in VB.NET when function has no return

前端 未结 5 2012
梦如初夏
梦如初夏 2020-12-06 19:47

Some comments on Stack Overflow question Why doesn\'t the C# compiler stop properties from referring to themselves? regarding warnings got me thinking about old issues that

5条回答
  •  -上瘾入骨i
    2020-12-06 20:15

    It's part of the BASIC language. All basic functions have a return type. If you do not specify a return type, then the type is assumed to be object.

    So the compiler can't warn you about a missing return, because it doesn't know if you skipped the return intentionally or because you were taking advantage of the default return value feature of the language.

    From this http://msdn.microsoft.com/en-us/library/sect4ck6(VS.80).aspx

    if you use Exit Function without assigning a value to name, the procedure returns the default value for the data type specified in returntype. If returntype is not specified, the procedure returns Nothing, the default value for Object.

提交回复
热议问题