This comes from this other question: ( How to build a method with unspecified amount of params en C# ). But since it's a different question I had to ask it here
Supposing you have a method overloaded (this overload is allowed by the compiler):
private static string AddURISlash(params string[] remotePaths) //multiple strings
private static string AddURISlash(string remotePaths) //single string
How should you know which will be executed when only one parameter is recieved?
Is there a convention? or something that you have to test once? Do I have to assume that since the only way to the single string method to be executed is to recieve a single string, that's the one that unequivocally be executed?
Thanks
How should you know which will be executed when only one parameter is recieved?
You read the specification, which explains how overload resolution is handled. From section 7.5.3.2, the relevant bullet point is:
Otherwise, if MP is applicable in its normal form and MQ has a params array and is applicable only in its expanded form, then MP is better than MQ.
So the version which doesn't require parameter array expansion (your single string version) is chosen at compile-time instead of the parameter array version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With