Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 110583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:14:59+00:00 2026-05-11T02:14:59+00:00

What are extension methods in .NET? EDIT: I have posted a follow up question

  • 0

What are extension methods in .NET?

EDIT: I have posted a follow up question at Usage of Extension Methods

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:15:00+00:00Added an answer on May 11, 2026 at 2:15 am

    Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type.

    Extension Methods help blend the flexibility of ‘duck typing’ support popular within dynamic languages today with the performance and compile-time validation of strongly-typed languages.

    Reference: http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx

    Here is a sample of an Extension Method (notice the this keyword infront of the first parameter):

    public static bool IsValidEmailAddress(this string s) {     Regex regex = new Regex(@'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');     return regex.IsMatch(s); } 

    Now, the above method can be called directly from any string, like such:

    bool isValid = 'so@mmas.com'.IsValidEmailAddress(); 

    The added methods will then also appear in IntelliSense:

    alt text
    (source: scottgu.com)

    As regards a practical use for Extension Methods, you might add new methods to a class without deriving a new class.

    Take a look at the following example:

    public class Extended {     public int Sum() {         return 7+3+2;     } }  public static class Extending {     public static float Average(this Extended extnd) {         return extnd.Sum() / 3;     } } 

    As you see, the class Extending is adding a method named average to class Extended. To get the average, you call average method, as it belongs to extended class:

    Extended ex = new Extended();  Console.WriteLine(ex.average()); 

    Reference: http://aspguy.wordpress.com/2008/07/03/a-practical-use-of-serialization-and-extension-methods-in-c-30/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ASP.NET MVC3 project and I am writing some extension methods that returns
I am trying to write extension methods in VB.NET Imports System.Runtime.CompilerServices Module ExtensionMethods <Extension()>
With .NET 3.5 a large amount of extension methods were added to the core
Background this post explains how one can consume extension methods in Powershell http://community.bartdesmet.net/blogs/bart/archive/2007/09/06/extension-methods-in-windows-powershell.aspx Compare
Possible Duplicate: What Advantages of Extension Methods have you found? All right, first of
is there a way in .NET (or some sort of standard extension methods) to
I just noticed on string they have a lot of extension methods that I
I have created a few WebRequest extension methods that support cancelling. Is it possible
I have added an extension method to the ASP.NET System.Web.UI.Page. Every page in my
We are currently discussing whether Extension methods in .NET are bad or not. Or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.