我有下面的代码片段什么“中立文化”打破了DateTime.TryParse()?
DateTime date1;
CultureInfo neutralCulture = new CultureInfo("fr");
bool isNeutral = neutralCulture.IsNeutralCulture; // True
DateTime.TryParse("not a date", neutralCulture, DateTimeStyles.AdjustToUniversal, out date1);
但是它执行未抛出异常,the documentation状态
NotSupportedException异常:提供商是一个中性文化,不能在分析中使用操作。
"fr"
是一个中性培养,通过上述CultureInfo
对象的属性所证明,所以我期望这个代码断裂。
什么“中性文化”打破了这种方法 - 这是在任何地方记录?
似乎在尝试将线程文化*设置为中立文化时抛出异常。我没有时间浏览所有的参考资源,但是您可能想自己钻研:(1)https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/datetime.cs和(2) )https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/globalization/datetimeparse.cs –
你为什么期待异常?如果字符串dpe不表示日期TryParse shpuld只是返回false ...我不完全理解文档中的注释,但在我看来,它并不指向您传递的字符串... – ATC
我我期待着一个例外,因为文档指出如果这个特定的参数是一个中立文化就会发生异常。 – Matt