Is a Guid a primitive type or a complex type? [closed]

爱⌒轻易说出口 提交于 2019-12-13 02:13:54

问题


We separate out extension method classes by primitive types and complex types that we are extending. My question is simple. Would a Guid be considered a primitive type along with string, int, DateTime, etc? Or would it be considered a complex type when describing it?

Update

After reviewing the answers I much appreciate the clarification that I was able to glean from some answers. However, I am getting the impression that curiosity killed the cat got the cat murdered, so I am voting to close my own question.


回答1:


It depends on what you call a "primitive data type".

Wikipedia lists these two definitions:

  • a basic type is a data type provided by a programming language as a basic building block. Most languages allow more complicated composite types to be recursively constructed starting from basic types.
  • a built-in type is a data type for which the programming language provides built-in support.

According to the first one, Guid is a constructed type, not a primitive.

According to the second, it is also not a primitive type (as it is provided in the BCL, in the System namespace, and is not defined by any of the .NET languages).


Update:

This is what the IsPrimitive method of the Type class says:

The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.

So, as far as .NET is concerned, it is not a primitive type.


In conclusion: According to the three separate criteria above, Guid is definitely not a primitive type.




回答2:


The answer to this is somewhat murky.

The language specification states:

it is also possible to use structs and operator overloading to implement new “primitive” types in the C# language

which would seemingly imply that Guid is a "primitive" type. However Type provides a IsPrimitive property and typeof(Guid).IsPrimitive will return false.

Note, though, that Guid is not provided by the language but rather by the .NET Framework.

The language specification also states that the primitive types in C# are Boolean (bool), Byte (byte), SByte (sbyte), Int16 (short), UInt16, Int32 (int), UInt32 (uint), Int64 (long), UInt64 (ulong), IntPtr, UIntPtr, Char (char), Double (double), and Single (single) notably leaving out both DateTime and Guid.

I would lose the descriptor "primitive" altogether and just refer to Guid as a value type.




回答3:


Guid would be a primitive by your definition. Its a struct like int, DateTime. Its also provided by the .NET Framework in the System namespace. Plus, its immutable, like string and DateTime.

By .NET's definion it isnt.

See http://msdn.microsoft.com/en-us/library/system.type.isprimitive.aspx

I would lump it in the same category as int, DateTime and string.




回答4:


It depends on what you call a "primitive type." The Type Fundamentals article says, "Any data types directly supported by the compiler are called primitive types.". I don't expect that the compiler "knows" about System.Guid.

The article Primitive data types in C# doesn't list System.Guid among the primitive types.

One could argue that it has to be a composite type, since it's a 128-bit entity that consists of multiple other primitives.

I'd say that GUID is NOT a primitive type, but you'll probably get others who disagree with me.



来源:https://stackoverflow.com/questions/7475884/is-a-guid-a-primitive-type-or-a-complex-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!