我必须用英文填写月份组合框:January、February 等。 我接下来是这样做的:
private string[] AmericanMonths
{
get
{
var arr = new string[12];
var americanCulture = new CultureInfo("en-US");
for (int i = 0; i < 12; i++)
{
arr[i] = new DateTime(2000, i + 1, 1).ToString("MMMM", americanCulture);
}
return arr;
}
}
comboMonth.Items.AddRange(AmericanMonths);
你怎么看,什么方式更好(性能)?
有没有办法将代表月份的整数转换成它的名字?
最佳答案
CultureInfo 已在框架中包含月份名称列表。你可以只写:
var americanCulture = new CultureInfo("en-US");
comboMonth.Items.AddRange(americanCulture.DateTimeFormat.MonthNames.Take(12)); //to remove last empty element
关于c# - 用英文月份填充组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/791734/