How to set optional parameter without compile-time constant

前端 未结 3 1652
攒了一身酷
攒了一身酷 2021-01-07 20:15

Is there a way to write the C# method below:

public string Download(Encoding contentEncoding = null) {
    defaultEncoding = contentEncoding ?? Encoding.UTF8         


        
3条回答
  •  北海茫月
    2021-01-07 20:40

    Use overloads:

    public string Download(Encoding contentEncoding)
    {
       // codes...
    }
    
    public string Download()
    {
        return Download(Encoding.UTF8);
    }
    

提交回复
热议问题