这个和基数之间的区别 [英] Difference between this and base

查看:36
本文介绍了这个和基数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想知道C#中 this base 对象之间的区别.使用它们时的最佳做法是什么?

I am interested to know the difference between this and base object in C#. What is the best practice when using them?

推荐答案

<代码>此 代表当前的类实例,而 基本 父级.用法示例:

this represents the current class instance while base the parent. Example of usage:

public class Parent
{
    public virtual void Foo()
    {
    }
}

public class Child : Parent
{
    // call constructor in the current type
    public Child() : this("abc")
    {
    }

    public Child(string id)
    {
    }

    public override void Foo()
    { 
        // call parent method
        base.Foo();
    }
}

这篇关于这个和基数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆