O código abaixo gera "fevereiro, fevereiro, fevereiro, fevereiro, fevereiro"
No entanto, estou tentando produzir os últimos 6 meses em uma base contínua - alguém pode ajudar?
Obrigado!
DateTime EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);//The AddDays function is self explanatory although you can have negative numbers in here
DateTime StartDate = EndDate.AddMonths(-1); //When do you want the meetings to start DateTime.Today will return midnight
DateTime m = StartDate.AddMonths(-6);
List<months> monthstore = new List<months>();
months monthdata = new months();
while (m < StartDate)
{
monthdata.month = m.ToString("MMMM");
monthstore.Add(monthdata);
m = m.AddMonths(1);
}
var publicationTable = new[] {
new[] { monthstore.Select(x=> x.month).ToArray() }
};
Respostas:
3 para resposta № 1colocar
months monthdata = new months();
no loop, você está mudando sempre o mesmo objeto. months
é um tipo de referência