. NET Knowledge Point Summary II (note consolidation)

Source: Internet
Author: User

19. What is a type?

It is used to define the size of a data in memory, and also to preset the method of manipulating this type of data.

What the 20.this keyword means when used in a method

  This refers to the object of the current class, or the object of the parent class's class (base can only point to the object of the parent class)

21. The Richter Replacement principle

  Sub-class replaces the location of the parent class

Data types in the 22.c#

    • Value type
      • Simple Type (numeric type (int,short,long,float,double), character (char), logical value (BOOL)), struct (struct), enum (enum)
    • Reference type
      • string, Array [],object (base class for all classes), class classes, delegate delegate

max. initialization of a value type variable (memory allocation)

1. member variables of a class

The variable is the object that follows the class that exists in heap memory. Destroyed when the object reference is broken, waiting for the garbage collector to clean up

2. Local variables of the method

The variable is present in the stack memory when the method is called, and is destroyed when the method is executed

inherit

  1), why should there be inheritance?

    A, improve the reusability of code

B, to achieve polymorphism

  

2). Limitations of inheritance

    A, a class can inherit only one parent class

B, subclasses can only inherit non-private members of the parent class

  

3) How a subclass accesses a non-private member of a parent class when there is an inheritance relationship

    A, base keyword: A pointer that exists in a subclass object to point to the parent class object

B, this keyword: Gets the non-private members of the parent class and members of this class

25. Subclass can be cast to parent class, but parent class cannot be converted to subclass

26, is and as the same and the difference?

  is to be judged, the return type is bool

As is the meaning of the conversion. As can only be converted to reference types. As is the first judgment in the conversion, first test whether the conversion is legal, if it is valid to convert, otherwise return null

Same: No exception is thrown

27, override and overload of the difference

A, overloading is the same as the name of the method. Different parameters or parameter types, multiple overloads to accommodate different needs

B, override is an override of a function in a base class. To adapt to the need

28. Override the "type" of the overridden method

Virtual method (Vritual): Must have method body

Abstract method: No method body

29, what is polymorphic?

is to instantiate the parent class with a subclass, call the abstract method/virtual method of the parent class, but actually execute the method that the subclass instance overrides

30. Abstract methods can only be defined in abstract classes

31, when there is an inheritance relationship, when the child class object is created, the parent class object is not created and there is only one object.

For example: Animal a = new Cat ();

When new is a subclass, there is only one subclass object

——————————————————————————————————————————————————————————————————————

And we often see this: the new subclass, when you first create a subclass object, call the subclass's constructor, create an object of the parent class, call the parent class constructor, and then return to execute the subclass constructor method. The subclass calls the non-parametric constructor method of the parent class by default, and if the parent class does not have an argument-free constructor, you must explicitly call ———— " This is a big mistake!"

  In memory, the concept of objects doesn't matter! New is based on the size of all the static members of the subclass and parent class, and the type pointer to open up a total space (the space does not contain methods), the child class and the parent class's type pointer to a method table of two classes, so that the subclass object can access the methods of the parent class and the child class.

32, if the child class and the parent class have a method with the same name but no overriding relationship, then call the parent class method if the call is called by the parent class variable, or call the subclass method if it is a subclass variable call . if the child class and the parent class have a method with the same name and an overriding relationship, then whatever type the variable is, the call is a method of the subclass.

33. The same and different points of virtual and abstract methods:

  Same point:

    Can be overridden by a quilt class and cannot be private

Different points:

1.abstract and virtual keywords are different

2. TheVritual method must be implemented, even if it is an empty implementation, and the abstract method must not be implemented

The subclass of the 3.virtual method can override the parent class method or not, and the subclass of the class where the abstract method resides must override the method of the parent class

4. Abstract methods must be declared in an abstract class, and virtual methods can exist in any class

34. The meaning of abstract class existence:

  Abstract class exists to specify the rules, rather than the implementation, is to constrain the behavior of subclasses, the implementation of the sub-class to complete.

35, the advantages of polymorphism:

  1. The internal layers of the code are relatively small and have fewer constraints on each other. (Low coupling)

2. The functions and responsibilities of the method are single, that is, one way to do only a thing. (High cohesion)

3. Implement code maintainability and extensibility, easy to develop two times

4. The different sub-class objects in front of the parent class, you can block the differences between different sub-categories of objects, write generic code, make a common program, in order to flexibly adapt to changing needs.

36. The base keyword in the subclass points to the parent class object. It is the subclass object itself, but his type is the parent class.

37. The following cases cannot be instantiated:

  Constructors for abstract classes, static classes, and classes have been privatized

38. Interfaces--Special abstract classes (the behavior of Constraints and uniform classes)

  Only methods, properties, indexers, and events are declared in the interface

Interface can only be used with public and internal two modifiers

Interfaces can implement multiple inheritance

If an abstract class inherits an interface, the inherited method can be set either as an abstract method or as an implementation method (either in the subclass of the abstract class or directly in the abstract class)

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.