Кодът по-долу извежда „февруари, февруари, февруари, февруари, февруари“
Обаче аз се опитвам да извеждам последните 6 месеца на подвижна основа - може ли някой да помогне?
Благодаря!
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() }
};
Отговори:
3 за отговор № 1слагам
months monthdata = new months();
в цикъла, вие променяте винаги един и същ обект. months
е референтен тип