Polymorphism
Polymorphism simply means "many forms" and hence means "having many forms" in C# or for that matter in any Object Oriented Programming language.
Method overloading and method overriding in C# implies one name with multiple functions. In method overloading and method overriding in C# we declare methods with the same name and different parameters in the same class or methods with the same name and same parameters in different classes.
There are two types of method overloading and method overriding in C#. They are the following.
Static Polymorphism
Method overloading and operator overloading are examples. It is also called early binding.
Dynamic Polymorphism
Method overriding and Virtual functions are examples. it is also called late binding.
Example of Method Overloading
- class Program {
- void hello() {
- Console.WriteLine("HelloIndia");
- }
- void hello(string s) {
- Console.WriteLine(s);
- }
- void hello(string s, int marks) {
- Console.WriteLine(s + " Your marks is " + marks);
- }
- public static void Main() {
- Program p1 = new Program();
- p1.hello();
- p1.hello("hello");
- p1.hello("siddique", 58);
- Console.ReadLine();
- }

So here we saw method overloading.
A method hello() that is declared in the base class A and not redeclared in classes B but B is inherited from A. So see the code and output.
- Program
- {
- class A
- {
- public void hello()
- {
- Console.WriteLine("helloWorld");
- }
- }
- class B: A {}
- public static void Main()
- {
- A a = new A();
- a.hello(); // output --> "helloWorld"
- B b = new B();
- b.hello(); // output --> "helloWorld"
- Console.ReadLine();
- }

The method hello() can be overridden in classes B.
- class Program
- {
- class A
- {
- public void hello()
- {
- Console.WriteLine("helloworld A");
- }
- }
- class B: A
- {
- public void hello()
- {
- Console.WriteLine("helloworld B");
- }
- }
- public static void Main()
- {
- A a;
- B b;
- a = new A();
- b = new B();
- a.hello(); // output --> "helloworld A"
- b.hello(); // output --> "helloworld B"
- a = new B();
- a.hello(); // output --> "helloworld A"
- Console.ReadLine();
- }

The output is not really what we, say from Java, expected. The method hello() is a non-virtual method. C# requires the use of the keyword virtual for a method to actually be virtual.
Example
- class Program
- {
- class A
- {
- public virtual void hello()
- {
- Console.WriteLine("helloworld A");
- }
- }
- class B: A
- {
- public override void hello()
- {
- Console.WriteLine("helloworld B");
- }
- }
- public static void Main()
- {
- A a;
- B b;
- a = new A();
- b = new B();
- a.hello(); // output --> "helloworld A"
- b.hello(); // output --> "helloworld B"
- a = new B();
- a.hello(); // output --> "helloworld B"
- Console.ReadLine();
- }

Method Hiding
C# not only supports method overriding, but also method hiding. Simply put, if a method is not overriding the derived method, it is hiding it. A hiding method must be declared using the new keyword. The correct class definition is as in the following:
- class Program
- {
- class A
- {
- public void hello()
- {
- Console.WriteLine("helloworld A");
- }
- }
- class B: A
- {
- public new void hello()
- {
- Console.WriteLine("helloworld B");
- }
- }
- public static void Main()
- {
- A a;
- B b;
- a = new A();
- b = new B();
- a.hello(); // output --> "helloworld A"
- b.hello(); // output --> "helloworld B"
- a = new B();
- a.hello(); // output --> "helloworld A"
- Console.ReadLine();
- }

Combining Method Overriding and Hiding
Methods of a derived class can both be virtual and at the same time hide the derived method. In order to declare such a method, both keywords virtual and new must be used in the method declaration as in the following:
- class A
- {
- public void hello() {}
- }
- class B: A
- {
- public virtual new void hello() {}
- }
- A class C can now declare a method hello() that either overrides or hides hello() from class B: class C: B {
- public override void hello() {}
- // or
- public new void hello() {}
- }
Only methods in base classes need not override or hide derived methods. All methods in derived classes require to be either defined as new or be overriden.

Amit Kumar SinghPosted Jan 16, 2021, 5:58 AM
Nice explanation !!
Ibrahim HaririPosted Sep 7, 2019, 6:23 AM
Thank you clear explanation.
jamshed alamPosted Jan 15, 2019, 5:11 AM
Thank you very much,very simple and clear explanation
Sunitha GugulothuPosted Sep 21, 2018, 7:00 PM
Thank you very much great explanation
Zunaid HossainPosted May 15, 2018, 4:39 AM
Dear Brother, Thank you so much. You teach us a complected topic with easiest way.
C# CornerPosted Apr 6, 2018, 12:23 AM
Dear Mukesh, You cover a complex topic in way that every one understand it fully. Thanks for the efforts. Stay Cool.
Mukesh KumarPosted Nov 25, 2015, 11:34 PM
Thanks to all
Praveen DhatrikaPosted Nov 25, 2015, 1:45 PM
Well Explained
Santhakumar MunuswamyPosted Nov 20, 2015, 8:59 AM
Good One
Suman VermaPosted Nov 20, 2015, 6:33 AM
nice one
Mukesh KumarPosted Nov 20, 2015, 5:48 AM
Thanks to everyone
Aishwarya DPosted Nov 20, 2015, 5:20 AM
Nice one. It will be very useful for beginners.
Ravi PatelPosted Nov 20, 2015, 5:14 AM
very nicely explained, thank you so much
Rajeesh MenothPosted Nov 20, 2015, 5:01 AM
Good Share!
Banketeshvar NarayanPosted Nov 20, 2015, 4:59 AM
Nice Share