0
public class MyClass:MyClassBaseClass, IInterface 
{
   public static method A()
   {
   }

   public static method B() 
   { 
   }
}

Consider the snippet above.

I want to implement an interface in my class. I want to make all the implemented methods from interface IInterface as static in my class so that I do not have to create an instance before calling the method. Why I am not allowed to do it and what are the possible solutions and workaround to do the same thing which I wish to do.

Kayathiri
  • 779
  • 1
  • 15
  • 26
Madhur Maurya
  • 1,016
  • 4
  • 19
  • 42
  • 1
    The workaround is the [Singleton Pattern](https://msdn.microsoft.com/en-us/library/ff650316.aspx) – Peter4499 Jun 07 '16 at 04:15
  • @AshwinNair Thanks for quick update. Is there a good way to achieve this ? – Madhur Maurya Jun 07 '16 at 04:30
  • 1
    Nothing using an `Interface` unfortunately. If you must use static methods, create a separate class for them since they'll probably be utility methods or use the singleton pattern as @Peter4499 suggested. He's even included a link :) . – Ash Jun 07 '16 at 04:45

0 Answers0