Let’s say I create these two methods:
public void AddScriptToPage(params string[] scripts) { /*...*/ }
public void AddScriptToPage(string href, string elementId) { /*...*/ }
Which one of these methods gets call by the code below, and why?
AddScriptToPage("dork.js", "foobar.js");
How does the compiler determine which method to call?
Your second method gets called, if an exact match is found, it’s used before params.
From MSDN:
When performing overload resolution, a method with a parameter array may be applicable either in its normal form or in its expanded form (Section 7.4.2.1). The expanded form of a method is available only if the normal form of the method is not applicable and only if a method with the same signature as the expanded form is not already declared in the same type.
Their example:
Output: