C ා language learning — data types


data type

Sbyte X; // 8bit, signed, represents - 128 ~ 127
Bit X; // 8bit, no sign, 0 ~ 255
Short X; // 16bit, signed integer
USHORT X; // 16bit, unsigned integer
Int x; // 32bit, signed integer
Uint X; // 32bit, unsigned integer
Long x; // 64bit, signed integer
Ulong X; // 64bit, unsigned integer
Float X; // 32bit
Double x; // 64bit, floating point number
Decimal X; // 128bit, precise floating-point number
Bool X; // 8bit, only true or false
Char X; // 16bit, character type
String x = "hello"; // String
(string name, int age) = ("Xiaoming", 24); // tuple
var people = (Name:"Xiaoming", Age:24 ); // another way to write tuples
String [] hi = {Hi "," hello "}; // declare array and initialize
Int [,] cells = New Int [3,3]; // declare a two-dimensional array
cells = {
}; // initializes a binary array
int[][] cells ={
    new int[]{1,1,1},
    new int[]{2,2}
}; // interleaved array 
System.Console.WriteLine (1.1234567899m); // specifies the literal value as the decimal type
System.Console.WriteLine (1_ 23444_ 567); // C ා 7.0, you can add a separator in the number

Several points for attention:

  • In C ා, short (USHORT) is a separate data type, while in C language it is the abbreviation of short int.
  • If a number is represented by the simplest fraction, and the denominator is not an integer power of 2, the precision will be lost if the scalar of float or double type is used to store it. And decimal type variables can guarantee precision. In addition, although the decimal type variable has 128 bits, its gram representation range is not as large as the float type.
  • In C language, the true or false of bool quantity can be replaced by non-zero or zero number, and C ා.
  • Char type variables have 16 bits in C ා and 8 bits in C language.
  • The string type is immutable. To modify a string, you can only create a new string in another memory location and then re assign it.
  • VaR is an implicit type. There are many ways to write tuples. I will not list them one by one.
  • Multidimensional array dimensions should be consistent