What does IFormatProvider do?

后端 未结 8 2195
一向
一向 2021-01-30 12:27

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

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

8条回答
  •  鱼传尺愫
    2021-01-30 12:40

    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);
    

提交回复
热议问题