Usage of Extension Methods in C# 3.5

Posted by Elizas under C# on 6/7/2010 | Views : 1740 | Status : [Member] | Replies : 3
Introduction: C# 3.0 provides a new feature called Extension Methods. Extension methods are methods that can be added to previously defined classes without rebuilding/compiling those classes.

Process: To define an extension method, we first define a static class, Then we define our static method which is meant to be extended. The first parameter of the extension class should be the type of Object we need to extend.

Syntax:
public static <Return Type> <Function Name>(this <Object Type> <Variable Name>)
{
Do Something
.........
......
return <Return Type> ;
}

http://www.mindfiresolutions.com/Usage-of-Extension-Methods-in-C-35-468.php




Responses

Posted by: Deeraj on: 6/7/2010 [Member] Starter

Up
0
Down
Hi Elizas

Please let me know on what's your question on extension methods that will need to be addressed?

Elizas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 6/10/2010 [Member] Starter

Up
0
Down
Post above code under Code or article section..

Elizas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 7/29/2010 [Member] Bronze

Up
0
Down
Are you facing any
problem or you just want to share with us?

One thing that you are missing that the class has to be also static

You can find the details related to Code of Extension at

http://www.dotnetfunda.com/codes/code891-method-extension-in-vs2008-and-vs2010.aspx

Elizas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response