C # Quick (2)

zhaozj2021-02-11  176

------------------- type of data -------------------

All C # data types are derived from base class Object. Here are two types of data types: basic / built-in user customizers

A list of C # built-in type below:

Type byte number explanation BYTE 1 No Symbol byte SBYTE 1 Symbolic Byte SHORT 2 Has Sign Short Texture Ushort 2 No Symbol Short Texture INT 4 Symbol Integer UINT 4 No Symbol Integer LONG 8 Symbol length ULONG 8 unsigned long integer float 4 floating point number double 8 double precision number decimal 8 fixed precision String Unicode string Char Unicode characters BOOL true and false Boolean

Note: The type range in C # is different from C ; for example, the LONG type of C is 4 bytes, while in C # is 8 bytes in C #. Similarly, the BOOL type and String are different from C . The BOOL type only accepts both of True and False. Do not accept any integer type. User-defined types include:

Class Type (CLASS) Structure Type (STRUCT) Interface Type (Interface)

Data types of memory allocation forms are divided into two types:

Value Types Reference Type:

Value type data is allocated in the stack. They include: all basic or built-in types (excluding String types), structural types, enumeration types (Enum Type)

Quote Type: The reference type is allocated in the heap, which will be collected by garbage when they are no longer used. They use the New operator to create, for these types, there is no DELETE operator in C , which is different from C explicitly use the DELETE this type of operator to release the created type. In C #, these types are automatically collected by the garbage collector.

The reference type includes: class type, interface type, set type type, string type, enumeration type

Enumeration Types are very similar to the concept of C . They are all defined by an enum keyword.

Example:

Enum weekdays {Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday}

Comparison of types and structural types In addition to the form of memory allocation, the concept of classes is completely with C . The objects of the class are allocated in the heap and create through New, but the structure is created by New but assigned in the stack. In C #, the structure is suitable for quick access and has a small number of data types. If there is more, you should create a class to implement him. (Translator Note: This is related to the characteristics of the allocation structure of the stack and the stack. In short, the stack is a sequential memory; the stack is not necessarily a continuous memory space. For details, you need to see the relevant information)

Example:

struct Date {int day; int month; int year;} class Date {int day; int month; int year; string weekday; string monthName; public int GetDay () {return day;} public int GetMonth () {return month; } Public int getYear () {return year;} public void setday (int day) {day = day;} {month = month;} public void setYear (int year) {year = year;} Public Bool IsleAPyear () {return (YEAR / 4 == 0);} public void setdate (int day, int month, int year) {} ...} -------------- ----- Attributes-------------------

If you are familiar with the way C iconic objects, you must have a concept of an attribute. In the above example, in the point of view of C , the attribute of the DATA class is DAY, MONTH and YEAR. With C # mode, you can write them into GET and SET methods. C # provides a more convenient, simple, direct way to access properties.

Therefore, the above class can be written:

Using system; class date {public int day {get {return day;}}} int day; public int month {get {return month;} set {month = value;}} int month; public int Year {get {return} set {year = value;}} int year; public bool isleApyear (int year) {return Year% 4 == 0? True: false;} public void setdate (int Day, int Month, INT year) {this.day = day; this.month = month; this.year = year;}}

You can get and set these properties here:

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

New Post(0)