Domanda

GetMonthName's virtual ToString method that inside DateTimeFormatInfo class is not working properly.I 'm adding culture code to CultureInfo but it is returning invariant value.

DateTimeFormatInfo d = new DateTimeFormatInfo();
d.GetMonthName(1).ToString(new CultureInfo("tr-TR")); // returns January
È stato utile?

Soluzione

GetMonthName returns a string. There is no translation that happens when you call toString on a string even if you provide a CultureInfo. What you want to do is something like this:

var trTr = new CultureInfo("tr-TR");
trTr.DateTimeFormat.GetMonthName(1);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top