Monday, 17 November 2025

Static Binding in C#

Static Binding in C#

Static Binding

Static binding, also called early binding, means that the method to be executed is determined at compile time. It is used in compile-time polymorphism such as method overloading and operator overloading.

Key Points:

  • Resolved at compile time.
  • Occurs in method overloading or operator overloading.
  • Faster than dynamic binding.
  • Opposite of dynamic (late) binding.

C# Example:

class Calculator { public int Add(int a, int b) { return a + b; } public double Add(double a, double b) { return a + b; } } class Program { static void Main() { Calculator calc = new Calculator(); Console.WriteLine(calc.Add(2, 3)); Console.WriteLine(calc.Add(2.5, 3.5)); } }

Output:

5 6

No comments:

Post a Comment