All I have described above are value types, so much so that I summarize the following what is called value type. Simply put, this type of variable stores the contained values directly. Here we are relative to the C language string, char ch[6] = "HC666"; The teacher said here is actually using CH to refer to the "HC666" address, access to the data through the address. String is the same, so strings in C # are reference types, not value types: Instead of the struct type, it is a value type by directly assigning variables to store the contents.
Enumeration (enum) Types of value types:
Enumeration (enum): In effect, a set of logically inseparable integer values that provide memorable symbols. For example, in the case of Sunday, I bought a movie ticket for the movie, the seat number is very good---66th, according to the number I found a position, a good position---2nd row 5th column, so happy to finish the film. In fact, this number 66th in my screening room is reflected in the 2nd row 5th column, this is called an enumeration.
declaring enum (enum) type variables:
Enum variable name { identifier list };
Attention:
In the list of identifiers, the elements are separated from each other by commas;
Each symbol in the enumeration list represents an integer value that is larger than the preceding symbol, and by default the first enumeration symbol represents 0, and of course it can be modified:
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Namespace Test { class program { //define enum type increments with 0 enum weekday { Sun, Mon, Tue, Wed, Thu , Fri, Sat //To change the default values simply (Sun = 2, Mon, Tue, Wed, Thu, Fri, Sat) Start with 2 increments of +1 }; static void Main (string[] args) { weekday Wek; Console.WriteLine ("Input 0~6 a number:"); int i = Int. Parse (Console.ReadLine ()); Wek = (weekday) I; Force type conversion, convert int type to weekday type Console.WriteLine ("{0} is {1}", I, Wek);} }
I enter a 0:
For coercion type conversions that occur in your code, I will write them out in the implicit conversion and display transformations that follow, and do not introduce them now.
Structure (struct) type comparison to enum (enum) Type:
I have a classmate. He is always a struct type and enum type innocently confused, sometimes write such error code to:
Enum wek{ int a,b,c; String d,e,f;}
To avoid the above mistakes, let me say the difference between them: in the case of struct type I have already mentioned that the data types in it can be of several different types, in other words, the struct type is a new set of types composed of different types of data, The value of a struct-type variable is a combination of the values of each member. Like what:
Struct wek{ public int a = 1; public int b = 2;}
Set a variable Wek w; At this point, W can either be used to indicate that the value of a is 1 (W.A), or that the value of B is 2 (W.B)
While enum (enum) types are different, variables of enumerated types can only take the value of one element of an enumeration list at a time, such as: In the program of the enum weekday I wrote earlier, Wek can only represent one value at a time, and it cannot represent both Sun and Mon at the same time.
Wek = (weekday) 2; At this time Wek can only represent Tue, can not express other.
These are the contents of the enumeration (enum) type of the C # Learning Diary---Data type, and more about topic.alibabacloud.com (www.php.cn)!