12-12 object-oriented-reference type and value type, namespace and class library, 12-12 namespace

Source: Internet
Author: User

12-12 object-oriented-reference type and value type, namespace and class library, 12-12 namespace

V. Reference Type and Value Type

. NET divides variable typesValue TypeAndReference Type. Variables such as int and float belongValue TypeAnd the "class" type variable belongsReference Type.

The value type is different from the variable of the reference type.

Variables of the value type can be used immediately after being defined.

After defining a variable of the reference type, you must use the new keyword to create an object.

For example, when two new objects are created, the bool value returned is false if the two objects are equal. because both objects are new space variables, they have no relationship with each other, and all objects are not equal.

2: 2) create the first new object ss1, assign values to the attributes in ss1, and then create the second new object ss2, directly compare ss1 and ss2, still not equal;

2) However, when "ss2 = ss1" is executed, if the object ss2 points to ss1, the value of ss1 is assigned to ss2. During the comparison, true is returned;

3) When ss2.Name is printed, the output value is the value of ss1.Name;

4) When you assign a value to ss2.Name again, the output value is the value of ss1.Name;

Vi. namespaces and Class Libraries

1. namespace: it is also called an assembly. It is equivalent to a folder and contains many classes (files ).

2. Class Library: a combination of many classes is equivalent to a compressed package composed of many files.

VII. Inheritance

One of the two classes that constitute the inheritance relationship is called the parent class or the base class, and the other is called the subclass. For example:

[Key understanding]: 1) subcategories include all attributes and methods of Fred;

2) All subclasses can be directly converted to the parent class type;

3) when the parent class type variable contains a subclass object, it can be converted to that subclass type.

Example:

[Example 1]: 1) create an object of the Ren class. Its field attributes include Name and Sex. (use the encapsulated field) the method is "speaking !"

2) create an object of the Men class as a subclass of the Ren class. Its field property inherits the Name and Sex attributes of the Ren class. The method is "making money ";

3) How to embody the inheritance relationship between the parent class and the Child class in the main function; through forced conversion, the Child class object is converted to the parent class, the attributes are not missing when the parent class is converted to a subclass (the attributes must exist in the parent class of a subclass );

[Note]: A parent class can contain multiple child classes, but a child class can only correspond to one parent class. The parent class and Child class can be understood as one-to-many relationships.

 

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.