C # concise tutorial (5) - Data type

zhaozj2021-02-17  82

C # concise tutorial (5)

C # data type

After the programmer gaves a programming language, the first thing is what data type it has, how to use them. In this section, I will introduce the C # data type and how to use them in the program.

◆ Basic data type

Most of the data types in C # are from the C and C languages. Please see the following table:

type of data

description

Example

Object

All other types of base classes

Object obj = NULL;

String

String Type - A Series of Unicode characters

String str = "mahesh";

Sbyte

8-bit has symbol integer

Sbyte Val = 12;

Short

16-bit is symbolic

Short Val = 12;

int

32-bit with symbol integer

INT VAL = 12;

Long

64-bit with symbol integer

Long Val1 = 12; long Val2 = 34L;

Bool

Boolean; UELE or FALSE two values

BOOL VAL1 = true; BOOL VAL2 = FALSE;

charr

Character type; Unicode character

CHAR VAL = 'h';

Byte

8-bit unsigned integer

BYTE VAL1 = 12; byte Val2 = 34u;

Ushort

16-bit unsigned integer

Ushort VAL1 = 12; Ushort Val2 = 34U;

Uint

32-bit unsigned integer

UINT VAL1 = 12; UINT VAL2 = 34U;

Ulong

64-bit unsigned integer

Ulong Val1 = 12; Ulong Val2 = 34u; Ulong Val3 = 56L; Ulong Val4 = 78UL;

Float

Single precision floating point

FLOAT VAL = 1.23F;

Double

Double precision floating point number

Double Val1 = 1.23; Double Val2 = 4.56d;

Decimal

High-precision 128-bit data type (for currency, etc.)

Decimal Val = 1.23M;

◆ Types in C #

C # support two types: numeric type and reference type

Types of

description

Numeric type

Including simple data types, it is better to speak int, char, bool, enums

Reference type

Includes objects, classes, interfaces, proxy and array types

Value type - numeric type object variables directly contain real data. For numerical types, each variable has a copy of their own data, and it is impossible to affect another variable by operating a variable. E.g:

INT i = 10;

Reference Type - Reference Type Variable Stores a reference to real data. For reference types, two variables point to the same object may be implemented, so it can affect the other variable by operating a variable. E.g:

Myclass cls1 = new myclass ();

◆ Data type conversion

C # supports two types of conversion, implicit conversion, and explicit conversion.

(1) Implicit conversion is direct conversion. E.g:

INT IVAL = 34; Long Lval = INTVALUE;

(2) Explicit conversion contains a mandatory type conversion. E.g:

Long lval = 123456; int = (int) LVAL;

转载请注明原文地址:https://www.9cbs.com/read-31373.html

New Post(0)