I. Integer type
C # defines the integer type in 8: byte, unsigned byte, short, and ushort) INTEGER (INT), none
Symbol INTEGER (uint), long integer (long), and unsigned long integer (ulong ). The division is based on the number of digits this type of variable occupies in the memory.
In C #, each integer type corresponds to a structure defined in the. NET class library.ProgramSet in system. The above structure provides two basic attributes: minvalue and maxvalue, respectively, representing the minimum and maximum values of the type.
Data Type |
Description |
Value Range |
Corresponds to the structure in the system assembly |
Sbyte |
Signed 8-digit integer |
-128 ~ 127 |
Sbyte |
Byte |
Unsigned 8-digit integer |
0 ~ 255 |
Byte |
Short |
Signed 16-digit integer |
-32768 ~ 32767 |
Int16 |
Ushort |
Unsigned 16-digit integer |
0 ~ 65535 |
Uint16 |
Int |
Signed 32-bit integer |
-2147483648-2147483647 |
Int32 |
Uint |
Unsigned 32-bit integer |
0 ~ 4294967295 |
Uint32 |
Long |
Signed 64-bit integer |
-9223372036854775808 ~ 9223372036854775807 |
Int64 |
Ulong |
Unsigned 64-bit integer |
0 ~ 18446744073709551615 |
Uint64 |
Integer value rangeCode:
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Namespace Integerrange
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Console. writeline ( " Value range of Integer type: " );
// Sbyte
Console. Write ( " Sbyte: \ t " );
Console. Write (sbyte. minvalue );
Console. Write ( " ~ " );
Console. writeline (sbyte. maxvalue );
// Byte
Console. Write ( " Byte: \ t " );
Console. Write (byte. minvalue );
Console. Write ( " ~ " );
Console. writeline (byte. maxvalue );
// Short
Console. Write ( " Int16: \ t " );
Console. Write (int16.minvalue );
Console. Write ( " ~ " );
Console. writeline (int16.maxvalue );
// Ushort
Console. Write ( " Uint16: \ t " );
Console. Write (uint16.minvalue );
Console. Write ( " ~ " );
Console. writeline (uint16.maxvalue );
// Int
Console. Write ( " Int32: \ t " );
Console. Write (int32.minvalue );
Console. Write ( " ~ " );
Console. writeline (int32.maxvalue );
// Uint
Console. Write ( " Uint32: \ t " );
Console. Write (uint32.minvalue );
Console. Write ( " ~ " );
Console. writeline (uint32.maxvalue );
// Long
Console. Write ( " Int64: \ t " );
Console. Write (int64.minvalue );
Console. Write ( " ~ " );
Console. writeline (int64.maxvalue );
// Ulong
Console. Write ( " Uint64: \ t " );
Console. Write (uint64.minvalue );
Console. Write ( " ~ " );
Console. writeline (uint64.maxvalue );
Console. writeline ();
}
}
}
Execution result:
Value range of Integer type:
Sbyte: - 128 ~ 127
Byte: 0 ~ 255
Int16: - 32768 ~ 32767
Uint16: 0 ~ 65535
Int32: - 2147483648 ~ 2147483647
Uint32: 0 ~ 4294967295
Int64: - 9223372036854775808 ~ 9223372036854775807
Uint64: 0 ~ 18446744073709551615
Press any key to continue...
If the type value exceeds the value range, the program will overflow during running.
Byte overflow code:
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Namespace Integrateoverflow
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Byte B = 100 ;
B = ( Byte ) (B + 200 ); // Overflow
Console. writeline (B );
}
}
}
Execution result:
44
Press any key to continue...
II,Source code
Integerrange.rar
Integrateoverflow.rar