I had thought that from the top of my head because I tried to use Array.IndexOf as an extension method and was surprised to see that it wasn’t an extension method.
It presented a good opportunity to play around with extension methods, so I wrote a class to extend the Array class:
It was so easy that I thought: “Why dind’t they do it?”.
While I was trying to write a proof of concept around making such a change in a class (changing normal static methods into extension methods). It was as simple as adding a this keyword:
The output of the compiler just chilled my enthusiasm:
Here’s how I had missed it:
I should have tried this:
THIS is the most recent (I think) specification of C# 3.0 and it states that:
Extension methods are declared by specifying the keyword this as a modifier on the first parameter of the methods. Extension methods can only be declared in non-generic, non-nested static classes.
Now it’s all clear!