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 typeAliased Type
sbyteSystem.SByte
byteSystem.Byte
shortSystem.Int16
ushortSystem.UInt16
intSystem.Int32
uintSystem.UInt32
longSystem.Int64
ulongSystem.UInt64
charSystem.Char
floatSystem.Single
doubleSystem.Double
boolSystem.Boolean
decimalSystem.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;

 

Page 8 of 17