日期:2008-09-23  浏览次数:20440 次

在论坛上经常看到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));}当时只是想这样的定义可以减少代码量,在调用时比较一致等,但是没想到还和缺省参数有关系