TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Annathurai Subbaiah
NA
510
2.1m
Extension Method Definition And Simple Example
Feb 19 2010 7:33 AM
Extension Method Definition:
1.It allows you to add new method to the existing class without modifying the code, recompiling.
2.It is special kind of static method but they are called using instance method syntax.
3.Extension method class should be static keyword and Method should have this keyword to invoke.
4.Extension method are only in scope when you explicitly import the namespace into your source code with 'using' directive.
Example of Extension Method:
namespace Extensionmethods
{
public static class ExtensionMethod
{
public static string Reverse(this string strReverse)
{
char[] reverseArray = new char[strReverse.Length];
int len = reverseArray.Length - 1;
for (int i = 0; i <= len; i++)
{
reverseArray[i] = strReverse[len - i];
}
return new string(reverseArray);
}
}
}
Calling Extension Method:
public void Page_Load(object sender, EventArgs e)
{
string strName = "annathurai";
string strResult = strName.Reverse();
Attachment:
Extension Method.zip
Reply
Answers (
2
)
image in datagrid
How to post a value from iframe to parent page?