Geeks With Blogs
Sonam Singh
I was trying to implement an Interface by a class but i wanted to have static methods.
But C# doesn't allow static methods in interface.
After a little search,I got "why We can't have static methods in Interfaces".
suppose i have an interface,
 interface IDemo
                static void add();
      Now we implement it:

 class MyClass:IDemo
            static void add()
Pretty cool na.
But it won't compile.
because what if  IDemo.add();
To avoid this ambiguity,
Static Methods are not allowed in Interfaces .


Although not implemented in C# the CLR does support static methods on interfaces. The drawback is that from C# you'd have to invoke them using reflection.

Posted on Thursday, December 18, 2008 6:03 PM .Net , C# | Back to top

Comments on this post: Static methods in Interface

# re: Static methods in Interface
Requesting Gravatar...
nice code, this problem is also wiith my project but what is solution on this ..

Left by abhishek on Aug 30, 2011 4:02 PM

Your comment:
 (will show your gravatar)

Copyright © sonam | Powered by: