What does IFormatProvider do?

Moulde picture Moulde · Feb 3, 2009 · Viewed 127.6k times · Source

I was playing around with the Datetime.ParseExact method, and it wants an IFormatProvider...

It works inputting null, but what exactly does it do?

Answer

Andrei Rînea picture Andrei Rînea · Feb 4, 2009

In adition to Ian Boyd's answer:

Also CultureInfo implements this interface and can be used in your case. So you could parse a French date string for example; you could use

var ci = new CultureInfo("fr-FR");
DateTime dt = DateTime.ParseExact(yourDateInputString, yourFormatString, ci);