El código de abajo produce "Febrero, Febrero, Febrero, Febrero, Febrero"
Sin embargo, estoy tratando de dar salida a los últimos 6 meses de forma continua: ¿puede alguien ayudarme?
¡Gracias!
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() }
};
Respuestas
3 para la respuesta № 1poner
months monthdata = new months();
en el bucle, estás cambiando siempre el mismo objeto. months
es un tipo de referencia