It cannot. It is part of the language specification. Static methods are methods belonging to the class and not the class instance (the object). An interface needs to have its methods implemented in the class instance. We can say that the concrete implementation in the class must inherit from the abstract statement existing in the interface. And you can’t use anything static to inherit anything.
Static methods need to be fully determined at compile time. The concrete implementation of the interface can be determined at runtime. There is no compatibility between these features.
Just to understand the difference between static and instance method:
the static method is like a normal function, it is called exactly that way as it is declared, essentially the compiler gives no special treatment to it. The only thing more that should be considered is that in his name includes the class name (you will not always see it but internally it is there);
the instance method hides the first parameter. You do not see it but always have a parameter called this
in it. This parameter is the instance. Using your example and considering that your class is called CloudStorage
it would be something like that:
You declare in class:
public CloudStorageAccount GetAccount()
And he compiles for:
public CloudStorageAccount GetAccount(CloudStorage this)
What you also don’t see in a method statement in the interface but it’s there is that every method in the interface is public and virtual. As they all are, there is no reason to declare it. Nor would it make sense if it were not so. And if the method is virtual, it must have a virtual table that will be dynamically accessed (according to the use in runtime). This table indicates which concrete type is being implemented in current use. This table is linked to the concrete type used by this
. Note that concrete type refers to the real type that your class was instantiated. With a static method this table does not exist after all the method does not belong to any instance.
To signature of a method static then is different from an instance method. It does not match, although it has the same name, it is not the same method. This is why the error seems to indicate something other than what is actually happening, so the compiler thinks that you have not declared the method.
Reply in the OS on the subject.
C# 8 that came out in 2019 allows static methods on interfaces (if all goes well). But it still only makes sense to call directly by type and not by instance. Thinking this was always possible, it just didn’t make much sense. As in C# 8 changes the philosophy of what the interface can do, it starts to make some sense. When leaving may ask more about the specific functioning.