Home  >  Article  >  Backend Development  >  In c#, the parent class calls the properties and methods of the subclass

In c#, the parent class calls the properties and methods of the subclass

巴扎黑
巴扎黑Original
2016-12-19 15:43:334221browse

We are used to thinking that the subclass is invisible to the parent class, or the parent class does not know the existence of the subclass, so the parent class cannot call the methods and attributes of the subclass. In the following way, the parent class can be implemented The function of calling subclass attributes and methods is welcome. . .

public class WeChatBaseController //Parent class

{

public WeChatBaseController()

{

}

public string MyUserList { get; set; }

var result = WeChat.GetPage(MyUserList)

}

public class WeChatWorkGroupController : WeChatBaseController //Subclass

{

Public WeChatBaseController BaseController;

Public WeChatWorkGroupController()

= "aaaaaaaaaaaaaa";

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn