This is really a comment to @Bruno's answer and may not be completely relevant to the question:
The decision to not allow partial methods to have multiple implementations is an arbitrary decision made in the design of the language. Your argument is a good reason why you might decide against allowing such a thing in your language but there isn't really a technical limitation. You can very easily decide to allow multiple implementation and let the compiler decide the order of execution of implementations. Actually, C# specification already has cases with undefined order for partial
classes:
// A.cs:
partial class Program {
static int x = y + 42;
static void Main() {
System.Console.WriteLine("x: {0}; y: {1}", x, y);
}
}
// B.cs:
partial class Program {
static int y = x + 42;
}
This is valid C# according to the C# Specification v3.0 but the output can be:
x: 42; y: 84
or
x: 84; y: 42
and the compiler is allowed to generate either of them. It doesn't even generate a warning.
The C# language requires a partial method to to have a void
return type. The partial method signature can be defined at most once. Likewise, the implementation should be defined at most once.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…