posts - 19, comments - 20, trackbacks - 0

My Links

News

Twitter












Archives

Post Categories

Static methods in Interface

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()
            {
                Console.WriteLine("Added");
            }
        }
Pretty cool na.
But it won't compile.
because what if  IDemo.add();
To avoid this ambiguity,
Static Methods are not allowed in Interfaces .

Note::

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.

Print | posted on Thursday, December 18, 2008 6:03 PM | Filed Under [ .Net C# ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: