In programming language, there are terms called method and function. But in C# we use the term "Method."
Method is a body where we put the logic to get some work done.
Here is the list of Method type in C#.
- Pure virtual method.
- Virtual method.
- Abstract method.
- Partial method.
- Extension method.
- Instance method.
- Static method.
Pure Virtual Method
Pure virtual method is the term that programmers use in C++. There is a term "abstract" in place of "pure virtual method" in C#.
Example:
- public void abstract DoSomething();
Virtual method makes some default functionality. In other words, virtual methods are being implemented in the base class and can be overridden in the derived class.
Example:
- public class A
- {
- public virtual int Calculate(int a, int b)
- {
- return a + b;
- }
- }
- public class B: A
- {
- public override int Calculate(int a, int b)
- {
- return a + b + 1;
- }
- }
Abstract Method is the method with no implementation and is implicitly virtual. You can make abstract method only in Abstract class.
Example:
- public void abstract DoSomething(int a);
A partial method has its signature defined in one part of a partial type, and its implementation defined in another part of the type.
Example:
- namespace PM
- {
- partial class A
- {
- partial void OnSomethingHappened(string s);
- }
- // This part can be in a separate file.
- partial class A
- {
- // Comment out this method and the program
- // will still compile.
- partial void OnSomethingHappened(String s)
- {
- Console.WriteLine("Something happened: {0}", s);
- }
- }
- }
Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type.
Extension methods are used to add some functionality to given type.
- For making Extension methods, you need to have a static class with static method.
- Do not make Extension method for one or two lines of code, write Extension method for logic.
E.g.
- public static class ExtensionMethods
- {
- public static string UppercaseFirstLetter(this string value)
- {
- //
- // Uppercase the first letter in the string.
- //
- if (value.Length > 0)
- {
- char[] array = value.ToCharArray();
- array[0] = char.ToUpper(array[0]);
- return new string(array);
- }
- return value;
- }
- }
- class Program
- {
- static void Main()
- {
- //
- // Use the string extension method on this value.
- //
- string value = "deeksha sharma";
- value = value.UppercaseFirstLetter();
- Console.WriteLine(value);
- }
- }
An instance method operates on a given instance of a class, and that instance can be accessed as this.
- public class PropertyUtil
- {
- public void DoSomething()
- {
- // Do Something.
- }
- public void DoSomethingElse()
- {
- this.DoSomething(); // Calling to instance method.
- }
- }
- public class Program
- {
- static void Main()
- {
- PropertyUtil util = new PropertyUtil();
- util.DoSomething(); // Calling to instance method.
- }
- }
This belongs to the type, it does not belong to instance of the type. You can access static methods by class name.
The only difference is that static methods in a non-static class cannot be extension methods.
Static often improves performance.
- public static class StaticClass
- {
- public static int DoSomething()
- {
- return 2;
- }
- }
- public class Program
- {
- static void Main()
- {
- StaticClass.DoSomething();
- }
- }


Hamza HamzaouiPosted Mar 13, 2020, 2:25 PM EDT
For Uppercase the first letter in the string it will crash if we have a space in the first letter so you should drop the first space from the string using data.Substring(1) and after that you can do your instructions.
Vinay SharmaPosted Jan 22, 2020, 10:58 AM EST
Good Explanation, Thanks
Ramzanali MominPosted Sep 27, 2018, 7:47 PM EDT
Nice article
Rahul SharmaPosted Oct 18, 2016, 1:49 AM EDT
Nice article
Manav PandyaPosted Oct 8, 2016, 4:20 AM EDT
Great post ma'm ...
SubashPosted Jul 5, 2016, 11:01 PM EDT
Thanks deeksha
Santhakumar MunuswamyPosted Jun 24, 2016, 9:08 PM EDT
Nice share
Samir BhogaytaPosted Jun 23, 2016, 6:53 PM EDT
Very nice explanation for beginners as well as experienced developers
Deeksha PanditPosted Jun 21, 2016, 7:35 AM EDT
Thank you all
Divyanshu SinghPosted Jun 20, 2016, 10:26 AM EDT
Great article
Del WoodcockPosted Jun 20, 2016, 6:47 AM EDT
Great information
Vignesh ManiTOP 100Posted Jun 19, 2016, 8:50 AM EDT
Good one. Thanks for sharing