How to set optional parameter without compile-time constant

前端 未结 3 1775
攒了一身酷
攒了一身酷 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:54

    public static string Download(Encoding encoder = null)
    {
        if (encoder == null)
            encoder = Encoding.Default
    
    
       string returnVal="";
       // do something
    
        return returnVal;
    }
    

提交回复
热议问题