Extension Class in C#

Extension method is a new feature in C# 3.0. 
Extension methods allow existing classes to be extended without relying on inheritance or having to change the class's source code. This means that if you want to add some methods into the existing String class you can do it quite easily.
Here's a couple of rules to consider when deciding on whether or not to use extension methods:
 
  1. Extension methods cannot be used to override existing methods.
  2. An extension method with the same name and signature as an instance method will not be called.  
  3. The concept of extension methods cannot be applied to fields, properties or events.
  4. Use extension methods sparingly....overuse can be a bad thing!

Comments

Popular posts from this blog

Enable HTTP Transport Security (HSTS) in IIS 7

When to use Truncate and Delete Command in SQL

Steps To Create New Project/Team On TFS