Today, in this article let's play around with one of the interesting and most
useful concept in C#.
are extension methods?
In simple terms "Extension methods are a special kind of static method, but they
are called as if they were instance methods on the extended type."
Step 1: Create
a new console application
Step 2: The
complete code of Arithmetic.cs looks like this
public static double Add(this double a, double
return a + b;
public static double Sub(this double a, double
return a - b;
public static double Mul(this double a, double
return a * b;
public static double Div(this double a, double
return a / b;
Step 3: The
extension methods showing in intellisense looks like this
Step 4: The
complete code of Program.cs looks like this
Result is: " + Arithmetic.Add(2, 2));
Result is: " + Arithmetic.Sub(2, 1));
Result is: " + Arithmetic.Mul(2, 5));
Result is: " + Arithmetic.Div(2, 12));
Step 5: The
output of the application looks like this
I hope this article is useful for you.
Everyone, It's Vijay. I am SDE mostly up on Microsoft Technologies. If
you are thinking to know what I do mostly when at work. I get a chance to work
upon few Microsoft technologies. All the way along my core tech... Read more
C# Corner. All contents are copyright of their authors.