Data Type (C #)
I also recalled the basic knowledge of C # language. My personal feeling is nothing more than two parts: basic process-oriented knowledge and basic object-oriented knowledge, among them, the object-oriented part extends a series of knowledge such as objects with the class as the core. the process-oriented architecture is based on data types and data operations. this is to review the knowledge of data types. for example:
The data type is just like this.
Below is the value type:Various value types always contain a value of the corresponding type
The integer type is as follows::
The real number type is as follows::
Character Type:
The character type in C # is a single UNICODE character. A unicode character is 16-bit long and can be used to represent multiple languages in the world. Assign a value to a character variable as follows: Char
Chsomechar = 'a ';
Note that there is no implicit conversion to convert the char type to other data types. This means that it is not feasible to treat a character variable as another Integer Data Type in C #. However, Explicit conversions can be used:
Char chsomechar = (char) 65;
Intnsomeint = (INT) 'A ';
Boolean(Bool)Type
The bool type corresponds to the system. boolean structure in the. NET class library. It occupies 4 bytes in the computer, namely, 32-bit storage space. The value can only be true or false,
You can assign true or false values to a Boolean variable or an expression. The obtained value is equal to one of the two:
Bool B = (80> 90 );
Structure Type
The process of organizing a series of related information into a single entity is the process of creating a structure.
It is usually used to encapsulate small correlation variable groups, such as rectangular coordinates or features of stock items.
The following example shows a simple structure declaration.
Public struct book
{
Public decimal price;
Public String title;
Public String author;
}
Enumeration type:
It is mainly used to represent a logically associated item and combination. Enum
The keyword is used to declare enumeration, which is a unique type consisting of a group of named constants called the list of enumerative numbers.
Generally, it is better to define an enumeration in the namespace so that all classes in the namespace can access it easily.
However, enumeration can also be nested in a class or structure.
By default, the value of the first enumeration is 0, and the values of each enumeration increase sequentially.
1.
For example, the following enumeration, Sat
Is 0, sun
Is 1, mon
Yes 2
And so on.
Enum days {sat, sun, Mon, Tue, wed, Thu, Fri };
The following example shows that the enumeration number can be an initial value to override the default value.
Enum days {sat = 1, sun, Mon, Tue, wed, Thu, Fri };
In this enumeration, force the element sequence from 1
Instead of 0
Start.
However, we recommend that you set the value to 0.
.
Each Enumeration type has a basic type, which can be a char
Any integer other.
The default basic type of enumeration elements is int.
To declare another integer enumeration (such as byte), follow the type after the identifier and then use the colon, as shown in the following example.
Enum days: byte {sat = 1, sun, Mon, Tue, wed, Thu, Fri };
The allowed enumerated types include byte, sbyte, short, ushort, Int, uint, long, or ulong.
Note:: The name of the enumerated number cannot contain white space
The following is the reference type:Compared with the value type, the reference type does not store the actual data they represent, but stores the reference of the actual data.
Class (Class)
A class is a set of objects with the same data structure (attributes) and the same operation (methods. The new keyword must be used to declare the instance for creating a class.
(Important) The fundamental difference between a class and a structure is that the structure is a value type, and the class is a reference type. For value types, each variable directly contains all its own data. Each time a variable is created, a zone is opened in the memory. For reference types, each variable only stores references to the data stored in the target. Each time a variable is created, a pointer pointing to the target data is added.
Interface (Interface)
To call each other between applications, an agreement must be reached in advance. the called party describes the services that it can provide in the agreement. In C #, this protocol is an interface. The method declaration in the interface definition does not include the access restriction modifier or the method Execution Code.
(Note) If a class inherits an interface, it must implement all services defined by the interface. That is, the method in the implementation interface.
Delegate
A delegate is used to encapsulate the call process of a method.
The use process of delegation is divided into three steps:
1. Define delegate void hellodelegate ();
2. instantiate hellodelegate Hd = newhellodelegate (P. Say); // method called by P. Say
3. Call HD ();
Array
Arrays are mainly used for batch processing of data of the same data type. In C #, arrays must be initialized before they can be used.
For example, int [] array1 = new int [3] {2, 3, 5 };
Int [] array1 = {2, 3, 5 };
(Note) for a rule multi-dimensional array, the value obtained by calling the Length attribute is the length of the entire array, and the getlength method is called. If the parameter is 0, the length of the array 1st dimension is obtained, if the value is 1, the length of the array is 2nd dimensions, and so on. For an irregular multi-dimensional array, call the Length attribute and call its getlength method with 0 as the parameter to obtain the length of the first dimension.