What is static binding in C#?


The linking of a function with an object during compile time is called static binding. C# provides two techniques to implement static polymorphism: Function overloading and Operator overloading.

In Function Overloading, you can have multiple definitions for the same function name in the same scope.

Example

void print(int i) {
   Console.WriteLine("Printing int: {0}", i );
}

void print(double f) {
   Console.WriteLine("Printing float: {0}" , f);
}

Overloaded operators are functions with special names. The keyword operator IS followed by the symbol for the operator being defineD.

Example

public static Box operator+ (Box b, Box c) {
   Box box = new Box();
   box.length = b.length + c.length;
   box.breadth = b.breadth + c.breadth;
   box.height = b.height + c.height;
}

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

612 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements