Var anonymous type the parent class uses a method virtual method of a subclass this and base

Source: Internet
Author: User

The Var anonymous type is based on the type's determined type when the field is initialized, and then cannot be changed.

Methods for adding classes for other projects. In the VS Class View, right-click to add a reference to select the item to refer to, and then add a using in the class to use the

If you use the parent class to initialize the enemy, you cannot force the conversion of the type

Enemy enemy;

Enemy = new Boss (); Initializes a parent class with a subclass, constructed with subclasses, essentially a subclass type

So the method that can be coerced into subclasses to use subclasses

This means that the parent class wants to use subclasses, and 1 needs to initialize 2 with subclasses to subclass

Boss Boss = (boss) enemy;

Boss. Attack ();

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

A virtual method can be overridden in any derived class subclass by declaring a base class function as virtual.

Overriding a method with the override keyword in a derived class

classmybaseclass{

Public virtual string Virtualmethod () {

}

}

________________

Class myderived

Public Overider string Virtualmethod () {

When a subclass overrides a method of a parent class, it is an overridden method, regardless of where it is invoked.

When initialized with the parent class, or before the original override method

This and base functions are to prompt, this prompts for features that are available to the current and parent classes, and base can only invoke the characteristics of the parent class

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.