You must Sign In to post a response.
  • Category: ASP.NET

    Extension methods in c#


    what is extension method ...can any one explain me with
    clear example ... and what is the differnce between extension method and normal method
    with example....
  • #725163
    Extension methods were introduced in 3.5 framework version of where we add methods to the class without changing the existing code of that class. There are used when we want to use the dlls of third party but need some changes in the existing method. So we create extension method.
    Please refer to the following link for more details:



  • #725186

    Using extension method you will be able to add methods without creating the new derived type to an existing types. Rather than me going through the complete details I would like you to read MSDN article for complete details:

    Asheej T K

  • #725257
    Extension methods are similar like other methods but it can be use to added classes without rebuilding or compiling .Syntax is given below
    public static class Extensions


    public static <Return Type> <Function Name>(this <Object Type> <Variable Name>)
    Write you requires
    return <Return Type> ;

    Example of Extension Methods

    public static class Extensions
    public static int ToInt32Ext(this string myvar)
    return Int32.Parse(s);

    public static int ToInt32(string myvar)
    return Int32.Parse(myvar);


    void Main()
    string myvar = "7";
    int Evar = myvar.ToInt32Ext();
    Evar = Extensions.ToInt32(myvar);

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.