[You must know. NET] The sixth time: in-depth keyword---base and this

Source: Internet
Author: User
Tags constructor inheritance

This article describes the following:

Object-oriented Basic concepts

Base keyword in simple words

This keyword in simple words

1. Introduction

The New keyword has aroused a lot of attention, especially thanks to Anders Liu's supplement, let me feel that the communication platform given by the blog is really ubiquitous. So it's necessary for us to go on with this topic and carry on the keywords I think are most noteworthy, and this article focuses on access to keywords (access Keywords): base and this. Although access to the keyword is not difficult to understand the topic, we still have in-depth discussion of the place to clarify ideas. Still the old way, my question is listed first, you are ready.

Can I use base and this in a static method, and why?

What are the base often used for? What is this commonly used for?

Can base access all members of the base class?

If there are three layers or more inheritance, what is the base of the most subordinate derived class pointing to that layer? For example. NET system, if you are using base access, should it be a direct parent class instance or a top-level class instance?

What is the order of execution of the inherited class object instantiation when applied to the constructor with base and this?

2. Basic Concepts

Base and this are attributed to access keywords in C #, as the name implies, to implement the access operation of the inheritance mechanism to satisfy the access to the object members, thus providing a more flexible approach to the polymorphic mechanism.

2.1 Base keyword

It is used to implement access to the base class public or protected members in a derived class, but only in constructors, instance methods, and instance property accessors, the specific features of the summary in MSDN include:

Invokes a method on the base class that has been overridden by another method.

Specifies the base class constructor that should be called when creating instances of the derived class.

2.2 This keyword

It is used to refer to the current instance of a class, as well as inherited methods, which can usually hide the summary features in THIS,MSDN, mainly including:

Qualify members that are hidden by similar names

Passing an object as a parameter to another method

Declaring indexers

3. In a simple and comprehensible

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.