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:
Here's a couple of rules to consider when deciding on whether or not to use extension methods:
- Extension methods cannot be used to override existing methods.
- An extension method with the same name and signature as an instance method will not be called.
- The concept of extension methods cannot be applied to fields, properties or events.
- Use
extension methods sparingly....overuse can be a bad thing!
Comments
Post a Comment