Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
AJAX
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
general knowledge
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 


How to use Extension Methods in C#
Question Posted on 12 Jan 2012

Home >> DotNet >> C# >> How to use Extension Methods in C#




Extension methods is a new feature of C# 3.0 that allows you to enhance an existing framework class by adding a new method to it without modifying the actual code of that class.Suppose you want to calculate the 4th power of an integer. For that you will have to square it two times. So instead of that you can create an Extension Method on integer
public static class ExtensionExample
{
  public static int powerfour(this int myNumber)
  {
    return myNumber ;
  }
}
Extension Methods are created in a static class and the Extension Method must be defined as static as shown above. The this keyword preceding the first parameter creates an extension method that applies to the type of that parameter. So here an Extension Method called Cube to the int type is created.
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


Other Important Questions
Simplest definition of partial classes and its rules?
Definition of Tuple class with some examples?
Define Race Condition in cSharp?
C#.Net Reserve Words
can we inherit private class level variables in c#






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |