2011-01-11 80 views

回答

1

Named and optional arguments在C#4中引入。这些参数允许开发人员编写更少的方法重载。

它们在处理COM互操作场景时也很有帮助。以下是来自MSDN的示例。

可选参数之前:

excelApp.get_Range("A1", "B4").AutoFormat(myFormat, Type.Missing, 
    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

可选参数后:

excelApp.Range["A1", "B4"].AutoFormat(Format: myFormat); 
相关问题