✅ ✅ Use function that has default implementation in interface from instance of class

BBinto862/10/2023
I have interface similar to this:
interface IFoo
{
  void DoThing1();
  void DoThing2();

  void DoMultipleThings(int thing1, int thing2)
  {
    for (int i = 0; i < thing1; i++)
    {
      this.DoThing1();
      for (int j = 0; j < thing2; j++)
      {
        this.DoThing2();
      }
    }
  }
}

now i have class like this:
class Bar : IFoo
{
  void DoThing1() => //something
  void DoThing2() => //something
}

and i want to use it like this:
Bar bar = new Bar();
bar.DoMultipleThings(5, 5);

is this possible? maybe some keyword on the interface or something (i know i can cast it, but i don't want to do that)
HHowNiceOfYou2/10/2023
You would need to either move the implementation of DoMultipleThings to the Bar class, or create a base class that implements the method.
BBinto862/10/2023
they can
HHowNiceOfYou2/10/2023
Wait, am I dumb?
HHowNiceOfYou2/10/2023
Hold on....
HHowNiceOfYou2/10/2023
You're correct, I apologise.
BBinto862/10/2023
ah thanks, i will just go abstract class than
HHowNiceOfYou2/10/2023
Your code should work?
AAccord2/11/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.