在论坛上经常看到C#里有没有缺省参数的问题,在 C# Team的blog 里看到 Eric Gunnerson 的一篇文章 Why doesn't C# support default parameters?
看完后想起原来用Reflector反编译看Int32的ToString函数的时候,三个重载的函数代码分别是:
public override string ToString()
{
 return this.ToString(null, null);
}
public string ToString(string format)
{
 return this.ToString(format, null);
}
public string ToString(string format, IFormatProvider provider)
{
 return Number.FormatInt32(this.m_value, format,
 NumberFormatInfo.GetInstance(provider));
}
|
当时只是想这样的定义可以减少代码量,在调用时比较一致等,但是没想到还和缺省参数有关系