DateTimeFormatInfo. InvariantInfo по сравнению с CultureInfo. InvariantCulture

rake routes в командной строке должен получить Вас тот список.

7
задан Binoj Antony 9 October 2009 в 04:49
поделиться

2 ответа

If you look at the signature for DateTime.TryParseExact, it takes an IFormatProvider as the third argument. Both DateTimeFormatInfo.InvariantInfo and CultureInfo.InvariantCulture implement this interface, so you are actually calling the same method on DateTime in both cases.

Internally, if you use CultureInfo.InvariantCulture, its DateTimeFormat property is called to get a DateTimeFormatInfo instance. If you use DateTimeFormatInfo.InvariantInfo, this is used directly. The DateTimeFormatInfo call will be slightly quicker as it has to perform less instructions, but this will be so marginal as to make no difference in (almost) all cases.

The main difference between the two approaches is the syntax. Use whichever one you find clearest.

8
ответ дан 6 December 2019 в 23:10
поделиться

They will give the same results.
And it is very unlikely there would be any difference in performance.

So use whatever you think is most readable. My choice would be DateTimeFormatInfo.InvariantInfo for being slightly more to the point.

3
ответ дан 6 December 2019 в 23:10
поделиться
Другие вопросы по тегам:

Похожие вопросы: