C # structure (struct)
The first structure is the value type data structure . It enables a single variable to store relevant data for various data types. The struct keyword is used to create structures. Popular says: A structure is a collection that can contain different data types. It is a data type that can be defined by itself.
Enumerations and structs are all value types, enumerations are often "literal" in real-life problems, easy to understand and intuitive, and second enumerated types can limit a type to a controllable range. And what about the structure? The structure makes it easy to handle collections of different data types, such as registering information for 100 students.
For example, the structure of defining student information is as follows: Initialize assignment considerations and learn later
1 public struct MyStruct // My students 2 { 3 public string Name; // name 4 public String mobilephone; // mobile phone 5 public DateTime Birthday; // birthday 6 }
To declare the information of Zhang Fei as follows, it is simple to declare the information of 100 students.
1 mystruct P1; 2 " Zhang Fei " ; 3 " 15358905577 " ; 4 P1. Birthday = DateTime.Now.AddYears (-);
A struct variable can be assigned to the same structure variable, and all the data held by that struct variable will be copied at the same time, and the following is a statement of the student information variable code as follows, P2 all data types to P1.
1 mystruct P1;2 mystruct P2;3P1. Name ="Zhang Fei";4P1. Mobilephone ="15358905577";5P1. Birthday = DateTime.Now.AddYears (- -);6 //assigns the value of the P1 to P2//because it is a value type, the assignment is equal to the stack space where all values are copied to P27P2 = P1;
C # 's first knowledge structure (struct)