根据 MSDN 文档和 .NET 源代码,您可以假设内置类型ToString()等同于ToString(null, null)和ToString("G", null)。
在 MSDN 上的 .NET Framework 中的格式化类型中有一些关于它的信息。
例如根据那个网站Int32.ToString()
调用Int32.ToString("G", NumberFormatInfo.CurrentInfo)以格式化Int32当前区域性的值。
如果您检查源代码,您会注意到ToString()调用
Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
String ToString(String format, IFormatProvider provider)通话时
Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
所以format实际上是null,不是"G"。但这并没有什么不同,因为"G"应该null是一样的。NumberFormatInfo.GetInstance(null)返回NumberFormatInfo.CurrentInfo,soInt32.ToString()等价于Int32.ToString("G", null)or Int32.ToString(null, null)。
您可以使用IFormattable.ToString文档仔细检查它,以查看nulls 确实表示两个参数的默认值。
参数
格式
要使用的格式。
-或者-
一个空引用(在 Visual Basic 中为 Nothing),用于使用为 IFormattable 实现的类型定义的默认格式。
格式提供者
用于格式化值的提供程序。
-或者-
一个空引用(在 Visual Basic 中为 Nothing),用于从操作系统的当前区域设置中获取数字格式信息。