Tip

On Extension Methods in C# and .NET Framework 3.5

As Visual Studio 2008 and the .NET Framework 3.5 spend more time in the wild, developers and architects are increasingly turning to the blogosphere both to see what the new IDE has to offer and to share lessons learned from the trenches.

One software architect in the latter category is Alex Hoffman, who recently wrote five blog posts under the heading "Adventures in .NET 3.5." In each post Hoffman shares a thing or two he has learned along the way.

Adventures in the .NET Framework 3.5, Part 1 takes a look at Extension Methods, which make it easy for an object to, as it were, print itself to the console. There's also a C# code snippet to implement concatenation once the aforementioned print method has done its thing.

More on Extension Methods in Visual Studio 2008
Visual Basic team offering Extension Methods tutorials 

Adventures in the .NET Framework 3.5, Part 2 expands on the Extension Method, demonstrating how it can be used to implement an Each method. Doing so gives C# code some of the same power as Ruby Blocks.

Adventures in the .NET Framework 3.5, Part 3 shows how the new compiler can infer a collection's type. Hoffman then provides some C# code for creating a public delegate, creating an Extension Method, and applying the Concatenate and Print methods to a collection.

Adventures in the .NET Framework 3.5, Part 4 builds on the Transform method form the previous post to do even more with the resulting collection.

Adventures in the .NET Framework 3.5, Part 5 (published with the headline "CodeDomProvider -- Targeting .NET 3.5" but tagged as a continuation of the adventure) offers the C# code needed to target the .NET Framework 3.5 if one is using a CodeDomProvider for code compilation. This is necessary because, by default, the CodeDomProvider targets the .NET Framework 2.0, Hoffman points out.


This was first published in September 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.