C # value type and reference type

Source: Internet
Author: User
Because of the differences between the row performance and the management of internal storage resources, the type is classified as value type and reference type.

The value type directly stores the value of this type in the stack. This type is more effective than the reference type in terms of internal use and failover.
The reference type changes point to the actual target image. Therefore, you must perform an internal reference operation to retrieve the data before accessing the object. The object of the reference type must be allocated multiple bytes of internal memory to store the parameter data and the synchronization between different processes. Therefore, the demand for internal storage is huge.

Take the Data Group as an example:
Data sets reference changes of the type, so the value changes. When a data group is used as a dynamic data set, its value also changes. This is because the address of the time when the type of parameter is referenced.
Note: string is also a reference type. It is more special than struct, and its value will not automatically change during initialization.
For example: Using System;
Class Mathod
{
Static   Void Printarr ( Int [] Arrlist)
{
For ( Int I = 0 ; I < Arr. length; I ++ )
{
Arrlist [I] = I;
}
}
Static   Void Main ()
{
Int [] Arr = { 100 , 200 , 300 };
Printarr (ARR );
Foreach ( Int I In ARR)
{
Console. Write (I + " , " );
}
Console. Readline ();
}
}

Result 1, 2, not 100,200,300

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.