crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)


How to use Extension Methods in C#
Question Posted on 12 Jan 2012Home >> 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




.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




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#






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap