DateTime.Now.ToUniversalTime().GetDateTimeFormats() returns Windows 7 和 Windows 10 上元素数量不同的数组

DateTime.Now.ToUniversalTime().GetDateTimeFormats() returns an array with different number of elements on Windows 7 and Windows 10

DateTime.Now.ToUniversalTime().GetDateTimeFormats()

当我运行在Windows7上执行上面的C#代码时,它returns一个有133个元素的数组,但是,当在Windows上执行相同的代码时10、它returns只有100个元素。是否有一种与文化无关的方式来访问元素,以便特定的日期格式始终出现在数组的固定索引处。

有没有我可以应用到 Windows 10 的补丁或修补程序,以便 returns 133 个元素,就像 Windows 7.

不,没有。文档中特别提到了这一点:

Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data. The data returned by this method can change if the current culture changes, the user overrides individual cultural settings, or an update occurs to the system's cultural data.

您可以使用此方法的重载来传递 IFormatProvider(例如 CultureInfo.InvariantCulture),但上述警告仍然适用。这不是一个无论出于何种原因都应该保留索引的列表。它可能会发生变化。