I am trying to achieve calling methods of the Base class and the Derived class. However, I am a little confused if I am doing it correctly. I would like to set values from the Base class and use them in the Derived class.
namespace Inheritance
{
using System;
public class BaseClass
{
public BaseClass() { }
protected string methodName;
protected int noOfTimes;
public void Execute(string MethodName, int NoOfTimes)
{
this.methodName = MethodName;
this.noOfTimes = NoOfTimes;
}
}
public class DerivedClass : BaseClass
{
public DerivedClass() : base() { }
public void Execute()
{
Console.WriteLine("Running {0}, {1} times", base.methodName, base.noOfTimes);
}
}
public class Program
{
static void Main(string[] args)
{
DerivedClass d = new DerivedClass();
d.Execute("Func", 2);
d.Execute();
Console.ReadLine();
}
}
}
Question: can I achieve the same as above using only 1 call to Execute instead of 2?
I hope my example above is clear. Please let me know if its otherwise and I will provide additional details.
Thanks
Executemethod in both the derived class and the base class by using a single call?