c sharp data type basics

  • 2020-05-05 11:47:57
  • OfStack

  1. value types value types include simple value types and compound types. Simple value types can be subdivided into integer type, character type, real type and Boolean type. A composite type is a composite of a simple type, including a structure (struct) type and an enumeration (enum) type. integer type

data type indicates that value range corresponds to sbyte structure in System assembly The signed 8-bit integer -128-127 SByte byte The unsigned 8-bit integer 0-255 Byte short Signed 16-bit integer -32768-32767 Int16 ushort The unsigned 16-bit integer 0-65535 UInt16 Int The signed 32-bit integer -2147489648-2147483647 Int32 uint The unsigned 32-bit integer 0-42994967295 UInt32 long Signed 64-bit integer -263-263 Int64 ulong The unsigned 64-bit integer 0-264 UInt64

character type C# USES the Unicode character set to represent character types. real type

data type value range float 32-bit single precision real number 1.5*10-45-3.4*1038 double 64-bit double real 5.0*10-324-1.7*10308 demcimal The 128-bit decimal real number 1.0*10-28-7.9*1028

Boolean (bool) type value can only be ture or false, bool type bool corresponding to the System.Boolean structure. It takes up four bytes, or 32 bits, of memory in a computer. structure type is the process of creating a structure by organizing a set of related information into a single entity. struct person { string m_name;       // name int m_age;                 // age string m_sex;             // gender } The enumeration type is primarily used to represent a logically associated item and combination. Use the keyword enum to define. enum Weekday { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} 2. reference types reference types include classes (class), interfaces (interface), delegates (delegate), and arrays (array). The class ( class ) class is a collection of objects with the same data structure and the same operations. An instance of the created class must be declared using the keyword new. The fundamental difference between classes and structures is that a structure is a value type and a class is a reference type. For value types, each variable directly contains all of its own data, and each variable created creates a region in memory. For reference types, each variable stores only a reference to the target store data, and each variable created adds a pointer to the target data. interface ( interface ) to invoke each other's applications, an agreement must be reached in advance in which the invoked party describes the services it can provide. In C#, this protocol is the interface. A declaration of a method in an interface definition that includes neither access restriction modifiers nor method execution code. If a class inherits an interface, it implements the services defined by that interface. That is, implement the methods in the interface. delegate delegate encapsulates the invocation of a method. The use of the delegate is divided into three steps: 1.           delegate void HelloDelegate(); 2. Instantiate HelloDelegate hd = new HelloDelegate(p1.Say); // method 3 called by p1.Say. Call           hd(); array array is mainly used for batch processing of data of the same data type. In C#, arrays need to be initialized before they can be used. For example: int[] array1 = new int[3]{2,3,5};               int[] array1 = {2,3,5}; (note) for regular multidimensional array, the value obtained by calling Length attribute is the length of the entire array; When the GetLength method is called, the length of the first dimension of the array is obtained when the parameter is 0, the length of the second dimension of the array is obtained when the parameter is 1, and so on. For an irregular multidimensional array, the length of the first dimension is obtained by calling the Length property and calling its GetLength method with 0 as an argument.             Explicit conversions from high-precision types are required.                                       long j = 1000;                     j = i;               // implicit conversion, Conversion from low precision to high precision                 i = (int)j; // explicit conversions, conversions with precision to precision the loss of information during the conversion depends on the accuracy of each data type. There is no implicit conversion between the enumeration type and any other type. Explicit conversions related to enumerated types include: 1. Explicit conversions from all integer types (including character types) and real types to enumerated types; 2. Explicit conversion from enumerated types to all integer types (including character types) and real types; 3. Explicit conversion from enumerated types to enumerated types. boxing and unboxing conversions is primarily a conversion between value types and reference types. For example: object obj 1= 10;           int i = (int)obj;             // unpack             int j = 100;           object obj2 = j;         // boxing conversion check if the conversion fails, the program throws an System.InvalidCastException exception