I’m wondering what is the difference for application between those two calls, in means of resulting DateTime object, whether TryParseExact will succeed, and result of ToString operation:
DateTime.TryParseExact(value, "MMM yyyy", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out conversionResult)
DateTime.TryParseExact(value, "MMM yyyy", null, DateTimeStyles.None, out conversionResult)
and those two calls:
conversionResult.ToString("d M yyyy", DateTimeFormatInfo.InvariantInfo)
conversionResult.ToString("d M yyyy")
I know that providing null will cause usage of thread culture info…
I just can’t work out what is the reason for specyfing Culture info when I explicitly provide format, without separators etc…
Thanks, Paweł
What month names would you expect it to use, just as an example of how culture can make a difference?
Sure, in some formats that won’t make a difference, but in others it will. For example:
Results:
(And that’s a relatively tame case.)
When you parse or format a string, you need to consider whether the source/target is a computer or a user. If it’s a computer, the invariant culture is probably most appropriate. If it’s a user, their culture is probably the most appropriate.