本文介绍了DateTime.ParseExact()比DateTime.Parse()更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道ParseExact是否比Parse快。



我认为它应该是ParseExact,因为你已经提供了格式,但我也认为所有的检查文化信息会减缓。微软在任何文件中都说两者之间的性能差异。要使用的格式是通用的yyyy / MM / dd格式。



例如:

  DateTime.Parse(DateText); 
DateTime.ParseExact(DateText,yyyy / MM / dd,CultureInfo.InvariantCulture);


解决方案

您要求两种方法的速度差异在功能上是不同的(接近但仍然不同)。



只需选择最合适的一个。



而不是,库方法的表现几乎从未被记录。



但是我可以告诉你一些关于这个差异的东西:





  • 可能会在以后的版本中更改


I would like to know if ParseExact is faster than Parse.

I think that it should be ParseExact since you already gave the format but I also think all the checking for the Culture info would slow it down. Does microsoft say in any document on performance difference between the two. The format to be used is a generic 'yyyy/MM/dd' format .

For example:

DateTime.Parse(DateText);
DateTime.ParseExact(DateText, "yyyy/MM/dd", CultureInfo.InvariantCulture);
解决方案

You are asking for the difference in speed for two methods that are functionally different (close but still different).

Just pick the one that is most appropriate.

And no, performance of library methods is almost never documented.

But I can tell you something about that difference:

  • it is small,
  • it might change in future versions

这篇关于DateTime.ParseExact()比DateTime.Parse()更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 07:42