Can extensions methods be called on no-object?

c#, extension-methods

Solution

Assuming you meant

bool test = sO.TestNull();

Then the answer is just that static functions do not need an instance of the object. Also, calling an extension function is just syntactic sugar for calling the function with parameters.

edit:

I recommend also reading Jon Skeet's answer.

Problem

Why does the following piece of code work? call: ``` SomeObject sO = null; bool test = sO.TestNull(); ``` code: ``` public static bool TestNull(this SomeObject sO) { return sO == null; } ``` Is this allowed to work or just a bug?

Original source

Related problems