Drill down into C # data types
--Different types of parameter passing use value passing, and changes to parameters in the method cannot be persisted after the call. Passed using ref mode, you can preserve changes to the parameter values. ---value way parameter passing and referencing is passed when the value type parameter is passed using the value method (without ref decoration), the modification of the parameter in the method is not persisted. When you reference a type parameter using a value method (without ref decoration), the modification of the parameter in the method is preserved. When you pass a value type and a reference type parameter by using a reference method (without a ref modifier), the modification of the parameter in the method is preserved.
Data types can be stored in two categories: value type (stack) and type of primer (heap)
Value types: Different variables allocate different storage space
Storage space stores the value of the variable
Changing a variable value does not affect the value of another variable
Reference type: Assignment is to pass the original object reference to another reference
Two references point to the same piece of memory space
Features of the structure
1 Value types
2 Faster data extraction (there can be fields in the structure or methods)
When the object requires less field representation, the structure can be selected
Structure is a value type, and the data extraction speed is fast
However, frequent assignment operations occupy a larger space, defined as classes in most cases of development
Conversion between a value type and a reference type
Packing
Value type------> Reference type
<------
Unpacking
Unnecessary packing and unpacking should be reduced in actual development
Because they are stored in different ways, the performance loss during conversion is significant
Pass a parameter without ref, pass a value, pass a copy, not change the original value
Add ref passes a value type by reference, passing a reference address, changing the original value
With value passing, in a method the value of the parameter is not preserved after the call, and is passed by ref, which can be reserved for the parameter values change
Value types and reference types. C # Common data types
Java C # shaping
int int floating point type
float float Double precision Line
Double Double string
Strinng string Boolean class
boolean bool Enum class
Enum enum
--The value type originates from the System.ValueType family, each object of value type has a separate memory area for storing its own value, and the memory area where the value type data resides is called the stack. As long as you modify it in your code, the value is saved in its memory area. Summary for value types, different variables will be allocated different storage spaces, and stored in the storage space is the value of the change amount. An assignment operation passes a value that is the value of a variable, and changing the value of one variable does not affect the value of another variable. --The application type originates from the System.Object family in C # Reference types mainly include numeric values, class interfaces, and so on.
Example-Classprogram{staticvoidmain (string[] args) {5int[] Infozhang =newint[] { the, -};//Zhang Hao's height and weight informationint[] Infoli=infozhang;//Value Reference Assignment 7Console.writline ("last year-Zhang Hao's height {0}, weight {1}", infozhong[0],infozhong[1]); Console.writline ("last year--Li Ming's height {0}, weight {1}", infoli[0],infoli[1]); infoli[0]= the; infoli[1]= -; Console.writline ("this year--Zhang Hao's height {0}, weight {1}", infozhong[0],infozhong[1]); Console.writline ("this year--Li Ming's height {0}, weight {1}", infoli[0],infoli[1]); 13console.readline ();}}
Array replication can take advantage of the loop implementation, which copies the values of the elements in the array arry1 to Arry2 for two arrays arry1 and arry2 (length of arry2 not less than arry1). --Subdivision value type and reference type value type--basic data type: int length type: Long float type: float double char bool enum class: Enum struct class: struct reference type-Class: base class: System.Object string: String Custom class: Class Interface: interface array: int [], string[]---structure definition: access modifier struct struct name {//struct} structure definition has the following characteristics-the structure can have a field, or can have data--when defined, A field in a struct cannot be assigned the use of an initial value structure you can declare a struct object without a new direct definition object, you must assign an initial value to the members of the struct-------boxing and unpacking
Summary: When you pass a value-type argument (without a ref modifier) when you pass a value, the modification of the parameter in the method is not preserved; When you pass a reference-type parameter (without a ref-decoration), the modification of the parameter in the method is preserved by using the value Pass ; When passing a value type parameter using a reference (without ref decoration) or when passing a reference type parameter, the modification of the parameter in the method is preserved, without the ref pass parameter, the value is passed, the reference is passed a copy, the original value is not changed, the value type is passed by reference, and the reference address is passed. Change the value of the original value type ====== "reference type----------Boxed reference type =====" values are passed--------the feature of the unboxing struct: value type data, without the new keyword has a faster data extraction speed structure with fields in it, You can also have a method (the field cannot be assigned the initial value directly)
Go deep into C #. NET data type