IntroductionI'm only writing about this because most people think that the signature concept is imposed by the CLR and this is not correct. If you see the behaviors of CLI you can see that it defines
* calling convention; * number of generic parameters (if the method is generic); * List of zero or more parameter signatures; * type signature for return result .
In C# , multiple methods with same name is allowed if each method’s input parameter / parameter set is different which we say method overloading.
In C#, the signature of a method is formed by its name and its parameter set.. But one important point for you is that the return type of a method isn't included on its signature! The following list exemplifies this concept: void HelloWorld();
void HelloWorld (int X); //This is Fine due to different parameter setvoid HelloWorld Method(int X,string Y);//Finevoid HelloWorld Method(string A, int B);//error same parameter set as previous methodint HelloWorld Method(int X); //error: can't overload based on return type only As you can see, even though the last method has a different return type from the second one, it still causes a compile time error which says that there's already a member with that signature.
I believe this is. Because overloading on return type is fine in MSIL but not in practically everything else, changing a method name so that it creates an a new overload on return type means it can't be disassembled back into something like C#. |