📜  c# base vs this - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:58.430000             🧑  作者: Mango

代码示例1
// The 'this' keyword represents the current class instance.
// While 'base' access's a method on the parent.

// Example of usage:
public class Parent
{
    public virtual void Foo() {}
}

public class Child : Parent // Derive from 'Parent' class
{
    public override void Foo()
    { base.Foo(); } // call the virtual method on 'Parent'

    // The override is basically not doing anything in this case, since we do
    // exactly the same thig as in the parent method (which in this case is nothing).
}