Possible Duplicate:
Why Doesn’t C# Allow Static Methods to Implement an Interface?
I have code like this that says I can’t implement a static methods:
public static class AuxiliaryHelper : IAuxiliaryHelper
{
/// <summary>
/// Writes the response.
/// </summary>
/// <param name="jsonObj">The json object that gets turned in JSON and written out.</param>
public static void WriteResponse(this object jsonObj)
{ ....
Can I get an interface for this?
Short answer: No.
Longer answer:
This concept doesn’t really make any sense. The point of an interface is to define a base type that describes a contract for various implementations. I can declare a variable using a static type of
IFoo, which tells the compiler I don’t know what type this will be at runtime, but I assure you it will have a certain set of methods. – Thus, the compiler will let you call those methods, which will be resolved at runtime.A static method is always bound to one and only one class, so there’s no instance to refer to.