Answers for "c# base vs this"

C#
0

c# base vs this

// 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).
}
Posted by: Guest on July-02-2021

C# Answers by Framework

Browse Popular Code Answers by Language