(Value Type reference type) Relationship with null, reference null

Source: Internet
Author: User

(Value Type reference type) Relationship with null, reference null
1. nullNull indicates that the variable does not point to any object.
2. Value TypeIncluding bool, struct, enumeration, int, double, float, and so on. The value types in. NET are inherited from ValueType.
3. Reference TypeIncluding strings, arrays, classes, interfaces, etc. The reference types in. NET are inherited from objects.
4. Reference Type and nullPerson p1 = new Person (); // The defined p1 does not point to any point at this time! P1 = null; p1.SayHi (); -------------- after executing the above Code, an exception is thrown directly. We are very familiar with not referencing the object to the object instance NullReferenceException. This is the relationship between the reference type and null. When a reference type is null, it means that he has no point.
5. Value Type and null// If this is the case in the project. Int num = null; // you don't have to wait to throw an exception because the compiler will directly report an error. Because the value type cannot be null. What if I want int num to be null? See 6th.
6. Empty data type.In. NET, by default. The data type that can be null is the reference type. The empty data type cannot be a value type. How can we control the value type? It can be written in this way. // Add? Indicates that the int type can be empty. It is called an int of the null type. Int? Num = null; // This method is widely used in Entity classes in database applications. A field in the database can be empty. // The attributes in the object class should also be empty. This is used.

 

Reference page: http://qingqingquege.cnblogs.com/p/5933752.html

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.