I have written a couple of app's that use LINQ, however, I realized that in order to talk about LINQ I would really have to have a brief look at the ICollections pattern and extension methods.

So extension methods are a really neat way to spot weld additional methods to existing classes in the .NET Framework. So for example, I recently talked about the HttpUtility.UrlEncode being buried in the System.Web namespace. Let us say that I wanted the UrlEncode method to be available where ever I use the String type, then I could do the the following:

public static class MDUtilities
{
	//Indicates that this method should be associated string
	public static string EncodeMyUrl(this string s) 
	{
		return System.Web.HttpUtility.UrlEncode(s);
	}
}

So by including the above class definition you now have a supercharged version of the string type as shown below.

extension method

Extension methods are littered throughout .NET 3.5 Framework and specifically in the ICollections pattern. These extension give us all the access to the LINQ goodness that we are starting to enjoy. So you can imagine somewhere in the .NET Framework would be a definition above that spot welds the new LINQ methods to ICollections.



Comment Section

Comments are closed.