SoFunction
Updated on 2025-04-06

Predefined types and reference types in C#

1. Predefined value types

One byte (1Byte) = 8 bits (8Bit)

The BitArarry class can manage bits Bit.

1. Integer

All plastic variables can be expressed in decimal or hexadecimal: long a=0x12AB

If a shaping value has not specified a type, the default is int type. You can add U, L, and UL suffixes to represent other types. long a=1234L

  • sbyte: Unsigned form: 1 byte (8 bits), range: 0 ~ 255 (28-1), hexadecimal representation: 0x00-0xFF,
  • byte  : Signed form: 1 byte (8 bits), range: -128 ~ 127 (-215 ~ 215-1), hexadecimal representation: 0x00-0xFF,
  • short  : Signed form: 2 bytes (16 bits), range: -32768 ~ 32767 (-231 ~ 231-1), hexadecimal representation: 0x0000-0xFFFF, System.Int16
  • ushort: unsigned form: 2 bytes (16 bits), range: 0 ~ 65534 (216-1), hexadecimal representation: 0x0000-0xFFFF, System.Int16
  • int : signed form: 4 bytes (32 bits), range: -231 ~ 231-1, System.Int32,
  • uint(U):Unsigned form: 4 bytes (32 bits), range: 0 ~ 232-1, System.Int32,
  • long(L): signed form: 8 bytes (64 bits), range: 263 ~ 263-1, System.Int64
  • ulong(UL): Unsigned form: 8 bytes (64 bits), range: 0 ~ 264-1, System.Int64

2. Floating point type

For a floating point value, the default is double type, and then F and M are added to specify it as other types.

  • float(F): Single-precision floating point number, 4 bytes (32 bits), decimal precision: 7, range: 1.5*10-45 ~ 3.4*1038,
  • double: double precision floating point number, 8 bytes (64 bits), decimal precision: 15/16, range: 5.0*10-324 ~ 3.4*10308 ,
  • decimal(M): 128-bit high precision, 16 bytes (128-bit), decimal precision: 28, range: 1.0*10-28 ~ 7.9*1028,

Rounding method:

decimal a1 = (("15.252"), 2);//12.25
decimal a2 = (("15.256"), 2);//15.26

3. Boolean type

  • bool: one byte (8 bits), range: true/false,

4. Character type (one character is represented by 2 bytes)

  • char: 2 bytes (16 bits), range: Unicode characters.

Character notation:

  • Literal method: char a=’x’
  • Hexadecimal method: char a=’\x0058’
  • Show conversion integer: char a=(char)88
  • Unicode form: char a=’\u0058’

2. Predefined reference types: object and string

Note: When string is used as a parameter of a function, it is a value-passing form, and the "ref" is still needed to be added to the address.

3. Predefined basic type conversion

https:///article/

This is all about this article about C# predefined types and reference types. I hope it will be helpful to everyone's learning and I hope everyone will support me more.