In C #, there are three data types: simple type, reference type, and class type.
Among them, the Data Types in simple types are roughly divided into: numeric type, integer type, decimal type, boolean type. They are familiar with VB, and it is no difficulty to transition to C # in learning. In addition, there are also the structure type and enumeration type in the value type. If you want to compare it with what is in VB, it is the custom data type.
Structure Type
The structure type is to combine different types of data for ease of use.
Using system; struct student {public int no; public string name; public string phone; public student (int stu_no, string stu_name, string stu_phone) {no = stu_no; name = stu_name; phone = stu_phone ;}} class structTest {public static void main () {// declare a student object student stu = new student (220722, "lhc", "12345678 "); console. writeline (stu. no); console. writeline (stu. name); console. writeline (stu. phone );}}
The description of the structure type and usage seem a bit similar to the class. They all indicate the data structures that can contain data members and function members, but the structure type is a value type, and the class type is a reference type.
Enumeration type
The enumeration type is a user-defined Integer type.
For example:
Enumweekday {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
The identifier in braces becomes an enumeration element. The enumeration element is of the int type by default. By default, the value of the first element is 0, followed by an ascending number.
The types assigned by enumeration elements are limited to integer types such as long, int, short, and byte.
Escape characters
In VB, if you want to control the line feed when entering a statement together, the ASCII code is generally converted into a response symbol through ch. However, transfer characters exist in C, C ++, C #, and even JAVA. Escape characters are often used in input and output streams to control the format of input and output content.
Note that when outputting characters with escape characters, you must add @ before the escape characters. Otherwise, the program will process the output characters as escape characters.
For example:
When there is no,
However, if @ is added, "/t" will not work, but will be treated as a common character:
Programmers complain about the trouble, but doing so makes the program safer and easier to avoid errors.
Binning
Packing: Convert the value type to the reference type;
Binning: converts a reference type to a value type;
Convert class
The value type and reference type are converted by unpacking and packing. In addition, the conver class can be used to convert between simple types.