简体   繁体   English

值类型和原始类型,以及非原始类型和引用类型有什么区别吗? 如果是,那么彼此之间有何不同

[英]Is there any difference Value Type and Primitive Type, and Non Primitive Type and Reference Type. If yes then how all are different from each other

C#: Is there any difference Value Type and Primitive Type, and Non Primitive Type and Reference Type. C#:Value Type和Primitive Type,Non Primitive Type和Reference Type有区别吗? If yes then how all are different from each other.如果是,那么它们之间有何不同。 I read it in C# documentation but it could clear my doubt about primitive and Non Primitive type.我在 C# 文档中阅读了它,但它可以消除我对原始类型和非原始类型的疑虑。

The C# specification, ECMA-334 , does not define the term Primitive Type . C# 规范ECMA-334没有定义术语Primitive Type It does have the term Simple Type .它确实有术语Simple Type There is also Type.IsPrimitive in the.Net Library. .Net库中还有Type.IsPrimitive

The CLR (.Net) specification, ECMA-335 , also doesn't define it, but it does have Built-In Types , however they are not quite the same as simple types from C#. CLR (.Net) 规范ECMA-335也没有定义它,但它确实有Built-In Types ,但是它们与 C# 中的简单类型并不完全相同。

Weirdly enough, ECMA-335 does specify simple types, but only for custom attribute constructors, and corresponds to Type.IsPrimitive .奇怪的是,ECMA-335 确实指定了简单类型,但仅适用于自定义属性构造函数,并且对应于Type.IsPrimitive

Value/reference types are somewhat orthogonal to that.值/引用类型与此有些正交。

  • Value Type值类型
    This is a CLR (.Net) term, and is the same as a struct in C#. It is passed by value (copy/value semantics).这是一个 CLR (.Net) 术语,与 C# 中的struct相同。它按值传递(复制/值语义)。

  • Reference Type参考类型
    This is also a CLR term, and is the same as class in C#. It is passed by reference.这也是一个 CLR 术语,与class中的 class 相同。它通过引用传递。

  • Simple Type简单型
    This is a C# term.这是一个 C# 术语。 It only includes struct s, and only the following are simple types:它只包括struct ,并且只有以下是简单类型:
    sbyte byte short ushort int uint long ulong char float double bool decimal . sbyte byte short ushort int uint long ulong char float double bool decimal
    Note that string and object are not in this list, even though they have alias names in C#.请注意, stringobject不在此列表中,即使它们在 C# 中具有别名。

  • Type.IsPrimitive
    This is the same list as above, except that it does not include decimal .这与上面的列表相同,只是它不包括decimal It is unclear what it is supposed to represent in the specifications.目前尚不清楚它在规范中应该代表什么。

  • Built-in types内置类型
    This is a CLR term, and refers to the same list as above, but also includes object , string (both of which are reference types) and TypedReference .这是一个 CLR 术语,指的是与上面相同的列表,但还包括objectstring (两者都是引用类型)和TypedReference

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM