Embedded Data Types - Object-Oriented Programming

Embedded Data Types

All embedded types of C # uniquely match the system types of the .NET Framework that are described in the System namespace. Therefore, wherever you can use a type name, for example int, you might as well use the name System.Int32. Description of the built-in types of C # language and their main characteristics are shown in Table. 3.1.

Table 3.1

The main characteristics of the built-in types of C # language

Type name

CLR System Type

Values ​​- Range

Size - accuracy

Boolean type

bool

System.Boolean

true, false

8 bits

Arithmetic Integer Types

sbyte

System. SByte

-128- + 127

Signed, 8 bit

byte

System. Byte

0-255

Unsigned, 8 bit

short

System.Short

-32768 - 32767

Signed, 16 bit

ushort

System.UShort

0 - 65535

Unsigned, 16 bit

int

System. Int32

≈ (-2 * 10 ^ 9 - 2 * 10 ^ 9)

Signed, 32 bit

uint

System.Ulnt32

≈ (0 - 4 * 10 ^ 9)

Unsigned, 32 bit

long

System. Int64

≈ (-9 * 10 ^ 18 - 9 * 10 ^ 18)

Signed, 64 bit

ulong

System. Ulnt64

≈ (0-18 * 10л18)

Unsigned, 64 bit

Arithmetic type with floating point

float

System.Single

+ 1.5 * 10 ^ -45 - + 3.4 * 1 ^ 38

32 bits (precision 7 digits)

double

System.Double

+ 5.0 * 10 ^ -324 - + 1.7 * 10 ^ 308

64 bits (accuracy 15-16 digits)

Arithmetic type with a fixed point

decimal

System.Decimal

+ 1.0 * 10 ^ -28 - + 7.9 * 10 ^ 28

28-29 significant digits

Character Types

char

System.Char

U + 0000 - U + fffff

16 bit Unicode character

string

System.String

A string of Unicode characters

Object type

Type name

System Type

Note

object

System. Object

The base type of all embedded and custom types

void

Absence of any value

In C #, all types - built-in and custom types - are associated with the inheritance relation (Figure 3.3).

The inheritance relation is described in detail. 5.2. The parent (base) class of all types is the Object class. All other types are its descendants, inheriting the methods of this class. The Object class has four inherited methods :

1) bool Equals (object obj) - checks the equivalence of the current object and the object passed as a parameter;

2) System.Type GetType () - returns the system type of the current object;

3) string ToString () - returns the string associated with the object; For arithmetic types, the value converted to a string is returned;

4) int GetHashCode () - serves as a hash function in the corresponding key search algorithms when storing data in hash tables.

Type Inheritance in the CLR Environment

Fig. 3.3. Type Inheritance in the CLR Environment

The child classes inherit all the properties and methods of the parent Object class. Naturally, all the built-in types as desired override methods parent and add your own fields, properties, and methods . Given that both types are created by the user, they are also class descendants of the Object , then they need to override methods parent, if you intend to use these methods ; the parent implementation provided by default does not provide the desired effect.

Ошибка в функции вывода объектов.