开发者

What is an intrinsic value type?

What is an intrinsic value type, and what is the difference to non-intrinsic value types?

I couldn't find documentation about the effect of the option "Function return开发者_运维百科ing intrinsic value type without return value." in Visual Studio's VB.Net project properties' Compile page.


You're right, there doesn't seem to be any documentation here.

Consider this code:

Module Module1

    Sub Main()
        Console.WriteLine("Foo() is {0}", Foo())

        Console.ReadKey()

    End Sub

    Function Foo() As Integer

    End Function

End Module

With the default project properties, which have "Function returning intrinsic value type without return value" set to Warning, this compiles with this warning:

warning BC42353: Function 'Foo' doesn't return a value on all code paths. Are you missing a 'Return' statement?

and outputs

Foo is 0

By setting That project property to Error, we can make this warning halt compilation with an error.

The 'intrinsic' part comes into play if we change the code to this:

Module Module1

    Sub Main()
        Console.WriteLine("Foo() is {0}", Foo())

        Console.ReadKey()

    End Sub

    Function Foo() As Bar

    End Function

End Module

Structure Bar
    Public a As Integer
End Structure

Now, even though Bar is a value type, the code compiles with no warning whatever that project property is set to. We can therefore conclude that Integer is an 'intrinsic' value type, but our Bar is not.

What none of this tells us is what counts as an 'intrinsic' value type. Googling around, I found this page which tells me that if I fire up the Object Browser, right click in the left-hand pane and tell it to Group By Object Type, I see this:

What is an intrinsic value type?

which I think is the best we're going to get.


"intrinsic" can be taken as "built-in" in this case.

And it seems not all that relevant, you are simply missing a return.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜