. NET Fundamentals Review (IV)

Source: Internet
Author: User

A Abstract class

1. The abstract method is modified with an abstract.

2. Abstract methods cannot have a method body, nor can braces.

3. The abstract method must be in an abstract class.

Examples of programs:

1 Abstract class  Person 2 3 {45                    Public Abstract void Sayhi (); 6 7 }

4. Abstract methods cannot be instantiated because there are abstract members, and abstract members have no method body.

5. Subclasses must override the abstract method of the parent class. (and virtual virtual method the biggest difference)

6. The abstract method of the parent class cannot be called from the base keyword in the subclass.

7. The abstract method is that the light says no, just defines the behavior, but the specific implementation is given to the subclass.

8. Abstract classes can have non-abstract members, in order to inherit to his child class.

9. You can have virtual methods in an abstract class.

10. Subclasses must override the methods of the parent class, and the parent class is not required to instantiate it, just use abstract classes.

11. Abstract classes are inherited, for polymorphism.

12. The abstract method cannot be private, because the subclass cannot be accessed, and there is no way to rewrite it.

two. Tostring and equals

1. The Equals method inside the object class compares the reference address of two objects and returns true if the reference address is the same.

2. The Equals method of the string type compares the contents of two string objects and returns True if the content is the same.

3. The Equals method of a reference type compares the address of two objects by default, and subclasses override if you want to change this rule.

4. String value type the value of the field in the two struct objects compared by the Equals method (this time there is no override, only the value type has its own new method).

Two Interface

1. Using interface to define an interface, the interface indicates that it has some kind of capability.

2. The essence of an interface is an abstract class, which is a special abstract class, so the interface cannot be instantiated.

3. The member in the interface is abstract by default.

4. Only properties, methods, indexers, events can be defined in the interface.

5. Abstract members cannot use the access modifier, which is public by default.

6. To implement an interface class, you must implement all the members of the interface.

7. The implementation class does not need to write the override keyword when implementing a member of an interface.

8. When implementing a member, you must ensure that the signature is consistent.

9. The interface is purely for the purpose of standardizing the implementation class.

10. Interfaces can be used by multiple groups with the same behavior but without a common parent class.

11. A class can inherit only one parent class, but it is possible to implement multiple interfaces, and the parent class is written in the first position, to some extent, solves the problem of the single root of the class.

12. Interfaces can inherit interfaces and can inherit multiple interfaces.

13. The members of the interface can be implemented as abstract or virtual methods, which facilitates the implementation of subclasses of the class to be rewritten.

14. The display implements the interface in order to resolve the problem of method name conflict, the method of displaying the implemented interface is private, so it cannot be called by the object's variable.

15. Display implementation interface, the implementation method of this interface can only be called through the interface variables.

16. Interface Usage Recommendations:

(1) interface--abstract class--class

(2) Avoid the definition of "bulky interface", "Multifunctional interface", will cause "interface pollution", only the associated set of members defined in one interface (as far as possible to define the number of members in the interfaces). (Single duty principle)

(3) Define multiple interfaces with a single responsibility.

Three Packing Box Unpacking

1. Boxing: Converts a value type to a reference type.

2. Unpacking: Converts the reference type to a value type.

Examples of programs:

1 int  A ; 2 3 object obj = i;   // Packing 4 5 i = (int) obj;        // Unpacking

3. Packing and unpacking are more consumption performance, we should try to avoid such behavior in our program.

. NET Fundamentals Review (IV)

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.