Liên kết hàm với đối tượng tại compile-time gọi là static binding. C# cung cấp hai kỹ thuật đa hình tĩnh: Function Overloading và Operator Overloading.
Function Overloading: nhiều định nghĩa cho cùng tên hàm trong cùng phạm vi.
Ví dụ
void print(int i) {
Console.WriteLine("Printing int: {0}", i);
}
void print(double f) {
Console.WriteLine("Printing float: {0}", f);
}
Operator Overloading: hàm với tên đặc biệt, từ khóa operator theo sau ký hiệu toán tử.
Ví dụ
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;
return box;
}