简体   繁体   English

如何在派生类中调用,访问基类的公共成员

[英]How to invoke, access public members of base class in derived class

I have 3 concrete classes named ClassA (that is built-in System.Web.UI.Page class), ClassB, and ClassC (see codes below). 我有3个具体的类,分别命名为ClassA(内置System.Web.UI.Page类),ClassB和ClassC(请参见下面的代码)。 ClassC is a dervived class of ClassB that is in turn is a derived class of ClassA. ClassC是ClassB的派生类,而ClassB又是ClassA的派生类。 ClassB has its own members. ClassB有自己的成员。 My question is how can ClassC invoke or access members (public properties, public methods) of ClassB? 我的问题是ClassC如何调用或访问ClassB的成员(公共属性,公共方法)? How are the scopes of classes solved in source codes of ClassC to avoid ambiguity? 如何在ClassC的源代码中解决类的范围,以避免产生歧义? Thanks in advance. 提前致谢。

Some codes: 一些代码:

// ClassA = System.Web.UI.Page
public class System.Web.UI.Page {
    // built-in class
}

public class ClassB : System.Web.UI.Page {
   // some own properties
   public bool IsUserLoginNameVisible { get; set; }

   // some own methods
   public void GetLoginUsers()
   {
   }
}

public class ClassC : ClassB {
   public int NumberOfLoginUsers()
   {
       // how can I invoke method "GetLoginUsers()" from ClassB in here?
       // base.GetLoginUsers() ???
   }

   public bool CheckToSeeUserLoginNameVisible()
   {
      // how can I access property "IsUserLoginNameVisible" from ClassB in here?
      // base.IsUserLoginNameVisible ???
   }
}

Derived classes inherit all accessible members from their base class. 派生类从其基类继承所有可访问的成员。

You can call them just like any other instance method. 您可以像调用其他任何实例方法一样调用它们。

The base keyword will force the call to resolve to the (immediate) base class' definition, even if your class shadows it, or your or derived class overrides it. base关键字将强制调用解析为(立即)基类的定义,即使您的类遮盖了它,或您的或派生类覆盖了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM