WHAT IS AN EXTENSION METHODS IN C#

Manoj Bhatt

Total Post:6

Points:30
Posted by  Manoj Bhatt
C#  ASP.Net 
C#
 612  View(s)
Ratings:
Rate this:
  1. Manoj Bhatt

    Post:6

    Points:30
    what is an extension methods in c#

    Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

    public static void Method1(this anotherclass ob) 
    {          
    Console.WriteLine("Hello I m extended method");
    }  
    you can access this Extension Method 'Method1' with using object of another class.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!