C#C
C#4y ago
Thinker

Calling a static abstract method without a generic type [Answered]

If I have this code with a static abstract member Bar in the interface IFoo, is there any way (besides reflection) to call Bar on an instance of IFoo without the explicit type of the instance?
IFoo f = GetFoo();
f.Bar(); // ???

static IFoo GetFoo() =>
  new Foo();

interface IFoo {
  static abstract void Bar();
}
class Foo : IFoo {
  public static void Bar() =>
    Console.WriteLine("bar");
}
Was this page helpful?