Geek Articles

Categories

 

Subscribe

Daily Updates Subscribe geekarticles update via email Subscribe geekarticles update via RSS

 
GeekArticles Database SQL Server

Extending Base Type Functionality with Extension Methods

Author: aspnet.4guysfromrolla.com | Published: 6th Dec 2007 | Visited: 121 times | Add Comment
Filed in: SQL Server

In November 2007, Microsoft released the .NET Framework version 3.5, Visual Studio 2008, and new versions of the C# and Visual Basic languages (see An Overview of ASP.NET 3.5 and Visual Studio 2008 for more details on the release). The new C# and Visual Basic versions include a myriad of exciting new features that make the languages more expressive and open the door for new syntax constructs, like LINQ. One of these new language features is extension methods, which is the topic for today's article. Extension methods allow a developer to tack on her own methods to an existing class in the .NET Framework. For example, imagine that our developer created a method named StripHtml, that strips HTML elements from a string using a regular expression. By associating this method with the System.String class, it could be called as if it was one of the System.String class's built-in methods: ' VB Dim str As String = "<b>Hello, world!</b>" Dim strippedString = str.StripHtml() // C# string str = "<b>Hello, world!</b>"; string strippedString = str.StripHtml(); Extension methods make it easy to add functionality to an existing type using a natural syntax. Also, since the extension methods appear in Visual Studio's IntelliSense drop-down list, they are easier to find and use than wrapper class equivalents. In this article we will see how to create extension methods in both C# and Visual Basic. Read on to learn more! Read More >

Read Article
 

Sponsored Links

 


Related Articles

 Adding Mouse Gesture Functionality to Your .NET Application Within Seconds This project allows you to add mouse gesture functionality to your Windows Forms application with just a few lines of c ...

 LINQ TO SQL All Common Operations (Insert,Update,Delete,Get) in ONE BASE Class Base Class to perform all Common LINQ To SQL Operat ...

 Change File Extension Context Menu An easy and flexible way to change file extensi ...

 Understanding SAO and CAO Activation Methods in .NET Remoting In this article Abhishek differentiates Server Activated Objects (SAO) and Client Activated Objects (CAO) in .NET Remoting. He examines the implementation procedures of these activation methods separately in Visual Basic 2005 using examples. Abhishek also provides the complete project along with the ...

 CheckBox ComboBox Extending the ComboBox Class and Its Items An article on a CheckBox ComboBox control which extends the ComboBox.It ...

 Creating XML with the DOM PHP Extension Creating XML with the DOM PHP Extension In fact, the PHP DOM extension is a set of classes that can be used to generate, access, and manipulate XML data. The DOM.php script defined in the following listing shows how to generate an XML document based on the result set retrieved from the database. Vi ...

 Source code generator for any data type How to extend Visual Studio so it can generate code for any data ...

 File Hash Generator Shell Extension Describes a shell extension option that calculates the file hash (SHA-1, MD5 etc.) of a file for use in verifying authentic ...

 See search results as you type - An ASP.NET Ajax Control A searchbox that updates the page with search results as you t ...

 C++0x Automates Type Deduction with auto Tired of typing unwieldy type names in variable declarations? Why not let the compiler do that dirty job, automatically deducing the type from the variable's initiali ...



Next: Accessing and Updating Data in ASP.NET 2.0: Handling Database NULL Values



Post Comment

Name:


Email:
 (Optional. Used for Notification)

Title:

 
Comment:


Validation Code:
 <=>  (Enter this code in text box)





Latest Articles

 

Popular Articles

Sponsored Links