Variables and Standard Types
What are primitive types?
The C# language includes a set of primitive types. These types are merely aliases for other types, but they have some additional properties that make then unique.
A primitive type, whilst is is an alias for an actual type, it can also be used as the value for a constant, and can be represented as a literal value in your code.
In the following example, the values of "1", "hello" are literals, as they are literally written into your code.
int one = 1; string hello = "hello";
C# supports the following primitive types:
Primitive type | Aliased Type |
---|---|
sbyte | System.SByte |
byte | System.Byte |
short | System.Int16 |
ushort | System.UInt16 |
int | System.Int32 |
uint | System.UInt32 |
long | System.Int64 |
ulong | System.UInt64 |
char | System.Char |
float | System.Single |
double | System.Double |
bool | System.Boolean |
decimal | System.Decimal |
You'll notice that string isn't a primitive type. Although the string type is an alias for System.String, and it can be used as both a value for a constant and a literal value in code, this is an implementation detail, rather than being a primitive type directly.
When you declare a type listed above, you can either use the type alias, or the source type:
int myAge = 30; Int32 yourAge = 30;