Dot net 3.5 Extension method and its usability

Hi,

Now when I have started working on dot net 3.5 the feature I love most is the extension method. I know many of you will be surprised that it’s not LINQ or the other new feature that are there in visual studio but this one. Well let me tell you how it let me code the way I want to (without leaving me to the limitation of the C sharp).

The kind of coder I am I use the Response.write() a lot. Whenever debugging some problem, for each response I have to add this line. But with extension methods I can add a new extension method to the object class to get this done pretty easily (and make my code look better).

Here is a simple extension method I created to help me out.

public static void Response(this object obj)

{
       Response.write (obj);
}

Now I do not have to write Response.Write. Instead I can write

int I = 9;

////Response.Write(I); ////No need for this now

I.Response();

Or

String str = “vikramlakhotia.com”;

////Response.Write(str); ////No need for this now

str.Response();

That is s much more cool and good looking. I ma really starting to like these feature in Dot Net framework 3.5. Way to go dot net team.

Vikram


Share this post   Email it

Feedback

Posted on 8/11/2007 8:53:10 AM

You may want to change your title for this post to "New Extension method in C Sharp 3.0, available in .NET FW 3.5"

C# is only in version 3.0. The .NET framework is in version 3.5.

Posted on 8/12/2007 9:50:23 PM

HI Toni,

sorry for the mistake. Corrected :-)

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2012 Vikram Lakhotia