C# – Extension methods vs. Static Class Methods

cextension-methodstatic methodsvisual studio

I've taken on a Visual Studio C# project where my previous colleague used a lot of Extension Methods in static classes over multiple files depending on the uses.

In my previous experience I would be more selective when using Extension methods but instead use a public static method in a static class.

It got me thinking if one is better than the other or does it really just come down to flavor or an industry standard that I am unaware of?

Thanks,

Best Answer

I think extension methods are more "discoverable". If I have a certain type, Intelli-sense will automatically give me the extension methods.

When a static class and method, I have to know the name of the static class so I can reference it. In small projects, this may not make a difference, but this larger projects with several directories and many different files, an extension method may be easier to discover and use for someone new.

Related Topic