Home >Backend Development >C#.Net Tutorial >What is static binding in C#?

What is static binding in C#?

PHPz
PHPzforward
2023-09-02 09:13:021063browse

C# 中的静态绑定是什么?

The linking of functions and objects during compilation is called static binding. C# provides two techniques for achieving static polymorphism: function overloading and operator overloading.

In function overloading, the same function name in the same scope can have multiple definitions.

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 is followed by the symbol used to define the operator for D.

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;
}

The above is the detailed content of What is static binding in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete