C# base 子类 访问 父类的 method 和 constructor 及 property 属性

在C#中,`base`关键字用于从派生类内部访问基类成员,如调用被重写的方法、指定实例构造器以及访问属性。它只能在构造器、实例方法或实例属性访问器中使用,并且在静态方法中使用`base`是错误的。
摘要由CSDN通过智能技术生成

The base keyword is used to access members of the base class from within a derived class:

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

  • Specify which base-class constructor should be called when creating instances of the derived class.

A base class access is permitted only in a constructor, an instance method, or an instance property accessor.

It is an error to use the base keyword from within a static method.

The base class that is accessed is the base class specified in the class declaration. For example, if you specify class ClassB : ClassA, the members of ClassA are accessed from ClassB, regardless of the base class of ClassA.

public class BaseClass
  {
    int num;

    public BaseClass()
    {
      Console.WriteLine("in BaseCla
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值