I have been studying C# lately and there is a thing called "predefined type". I thought it is another name of the primitive type. But my friend told me that those are quite different from each other. Just got confused.
Are these two names for the same thing, or are they totally different?
In the Type.IsPrimitive documentation page there's a complete list of primitive types:
The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.
And section 1.2.1 (Predefined types) clearly makes the difference between these and predefined reference types:
The predefined reference types are
object
andstring
. The typeobject
is the ultimate base type of all other types. The typestring
is used to represent Unicode string values.
So I guess it's quite obvious they are different - at least, in .NET terminology.
Predefined are the types that are specially supported by the compiler. They alias .NET framework types in the System namespace. They are also called built-in types.
How are they supported by the compiler? They have their own keyword. For example int keyword is used to predefine System.Int32 type. This means that when you define an integer variable in C#, you can do so by typing:
int myIntVar = 3;
instead of
System.Int32 myIntVar = 3;
This is only syntatic difference though.
Primitive types are all predefined value types minus decimal type. I made a sketch that demonstrates this:
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With