-3

Why calls the compiler only the second function and not the first? I have no idea why it's taken the second function.

WriteLog("string", "string2" , "string3", "string4");

public static void WriteLog(string text, params string[] pAktionInfos)
{
    WriteLog(text, pAktionInfos);
}

public static void WriteLog(string text, string text2, params string[] pAktionInfos)
{
    if (string.IsNullOrEmpty(text2))
    {
        //Awesome Code
    }
    //Another Awesome Code
}
gunr2171
  • 16,104
  • 25
  • 61
  • 88
Peiper
  • 56
  • 9

2 Answers2

4

Only one function can be called and the compiler calls the one that is closest to the original signature and most specific.

You should get a warning about those two functions anyway. If you don't, turn up your warning level.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
1

Because in the compiler the order of recognition goes from explicit parameters to parameters defined with params. The more specific a signature is, the sooner it matches.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325