Drill down into C # data types: Value (no ref) + value = invariant value (no ref) + citation = variable (with ref) + value/citation = variable
1. Value types and reference types
1. Reference types
Originated from the System.Object family.
(1) class
(2) Interface: interface
(3) array
(4) Strings: string
:
2. Value types
Originated from the System.ValueType family
The memory area where the value type data resides is the stack.
3. Value type:
(1) Basic data type {int,long,double,byte~~~~}
(2) Enum: enum
(3) Structure: struct
2. Structural body
1. Definition:
Access modifier struct struct name
{
Structural body
}
(1) Structs can have fields, methods, fields cannot be assigned initial values.
(2) can not new, but conditional, the struct has member variables and member methods, member variables are not assigned, call member methods, not new will error, so generally first new.
For example:
public struct student{public int num; public void Show () {}}
static void Main (string[] args) { Student stu; stu.num; stu.show (); }//Does not assign a value to the member variable, error
static void Main (string[] args) { Student stu; stu.num=10; stu.show (); }//Assign value to member variable without error
static void Main (string[] args) { Student stu=new Student (); stu.num; stu.show (); }//new out, no error
3. Crating and Unpacking
Tip: Try to reduce boxing and unpacking as they consume the program's performance.
Chapter II in-depth C # data types