C # Data types
In C #, variables are divided into the following types:
- Value type
- Reference type
- Pointer type
Value type
Value type variables can be directly assigned to a value, and they are derived from the class System.valuctpyc.
Value types directly contain data, such as int, char, and float, which store numbers, letters, and floating-point values, respectively. When you declare an int type, the system allocates memory to store the value.
The following table lists the value types:
| type |
Description |
Range |
Default Value |
| bool |
Boolean value |
True or False |
False |
| Byte |
8-bit unsigned integer |
0 to 255 |
0 |
| Char |
16-bit Unicode characters |
U +0000 to u +ffff |
' + ' |
| Decimal |
128-bit exact decimal value, 28-29 significant digits |
( -7.9 x 1028 to 7.9 x 1028)/100 to 28 |
0.0M |
| Double |
64-bit double-precision floating-point |
(+/-) 5.0 x 10-324 to (+/-) 1.7 x 10308 |
0.0D |
| Float |
32-bit single-precision floating-point |
-3.4 x 1038 to + 3.4 x 1038 |
0.0F |
| Int |
32-bit signed integer type |
2,147,483,648 to 2,147,483,647 |
0 |
| Long |
64-bit signed integer type |
923,372,036,854,775,808 to 9,223,372,036,854,775,807 |
0L |
| SByte |
8-bit signed integer type |
128 to 127 |
0 |
| Short |
16-bit signed integer type |
32,768 to 32,767 |
0 |
| UInt |
32-bit unsigned integer type |
0 to 4,294,967,295 |
0 |
| ULong |
64-bit unsigned integer type |
0 to 18,446,744,073,709,551,615 |
0 |
| UShort |
16-bit unsigned integer type |
0 to 65,535 |
0 |
If you need to get the exact size of a type or a variable on a particular platform, you can use the Sizcof method. The expression sizeof (Tpye) produces storage dimensions that store objects or types in bytes. Below violently get any machine on the INT storage size:
using System; namespace datatypeapplication{ class program { staticvoid Main ( string [] args) { System.Console.WriteLine ("Size of int:{0}",sizeof( int)); System.Console.ReadKey (); }}}
Compile results
Learn c#--data type from scratch (iii)