C # predefined data types (detailed description of value types and reference types)

Source: Internet
Author: User
C # The basic pre-defined type of recognition is not built into the language, but is built into the. NET Framework. For example, declare an int
The declared data type is actually an instance of the. NET structure system. int32.
C # divide data types into two types
I. Value Type
Basic Data Type
Ii. Reference Type
1. Object. in C #, object is the final parent type. All internal and user-defined types
Derived from. You can bind an object to any sub-type object, and perform many basic operations on the object type.
.
2. String, for example:
String str1 = "hello ";
String str2 = "world ";
String str3 = str1 + str2;
Although this is a value type assignment, string is a reference type. The string object is retained on the stack,
Instead of the stack. Therefore, when a string variable is assigned to another string
Two references of the same string. However, there are some differences between string and reference types in common operations.
For example, if you modify one of the strings, A New String object will be created, while the other string does not
Change.
C # has 15 predefined types, including 13 value types and 2 reference types (string and object ).
In terms of concept, the difference is that the value type directly stores its value, while the reference type storage object is worth referencing.
Stored in memory:
The value type is stored in the stack, and the reference type is stored in the managed stack.
Related Article

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.