什么是内在价值类型? [英] What is an intrinsic value type?

查看:25
本文介绍了什么是内在价值类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是内在值类型,与非内在值类型有什么区别?

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

我找不到有关函数返回内在值类型而没有返回值"选项的效果的文档.在 Visual Studio 的 VB.Net 项目属性的编译页面中.

I couldn't find documentation about the effect of the option "Function returning 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.

考虑这个代码:

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:

警告 BC42353:函数Foo"不会在所有代码路径上返回值.您是否遗漏了退货"声明?

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

和输出

Foo 为 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

现在,即使 Bar 是一种值类型,无论项目属性设置为什么,代码在编译时都不会发出警告.因此,我们可以得出结论,Integer 是一个内在"值类型,但我们的 Bar 不是.

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:

我认为这是我们将要得到的最好的.

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

这篇关于什么是内在价值类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆