Posts

Showing posts with the label Polymorhism in C#

Polymorhism in C#

Polymorphism (meaning "many forms") is a fundamental concept in object-oriented programming (OOP) that allows objects of different classes to be treated as objects of a common type. In C#, polymorphism is achieved through two main mechanisms:   1. Compile-Time Polymorphism (Static Polymorphism/Overloading): This type of polymorphism is resolved at compile time. It's achieved through method overloading and operator overloading. Method Overloading: Defining multiple methods within the same class with the same name but different parameter lists (different number, types, or order of parameters). The compiler determines which method to call based on the arguments provided during the method call. C# public class Calculator { public int Add ( int a, int b ) { return a + b; } public double Add ( double a, double b ) { return a + b; } public int Add ( int a, int b, int c ) { return a + b + c; ...