命名引數可以使你的程式碼更清晰
考慮這個簡單的類:
class SmsUtil
{
public bool SendMessage(string from, string to, string message, int retryCount, object attachment)
{
// Some code
}
}
在 C#3.0 之前,它是:
var result = SmsUtil.SendMessage("Mehran", "Maryam", "Hello there!", 12, null);
你可以使用命名引數使此方法呼叫更加清晰 :
var result = SmsUtil.SendMessage(
from: "Mehran",
to: "Maryam",
message "Hello there!",
retryCount: 12,
attachment: null);