Method Overloading with Optional Parameter

前端 未结 3 1114
甜味超标
甜味超标 2021-01-17 07:56

I have a class as follows with two overload method.

Class A
{
    public string x(string a, string b)
    {
        return \"hello\" + a + b;
    }

    publ         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 08:06

    It will always execute method which first match with exact no of parameters, in your case it will execute :

    Optional parameter method priority is less then the function with exact no of parameters

    public string x(string a, string b);
    

提交回复
热议问题