I'm trying to create a method that returns me a DateTime object.
This date should be the last day of the previous month (month is given by me).
Example:
Month: january (1)
Year: 2019
What I need: 31/12/2018
This is what I have
public DateTime getLastDayPrevMonth(int month, int year)
{
DateTime date = new DateTime();
date.Month == month;
date.Year == year;
date.AddMonths(-1);
date.Day = DateTime.DaysInMonth(date.Year,date.Month);
return date;
}
but it returns the error:
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
What am I doing wrong?
date.Month == monthyou wantdate.Month = month(same for Year) - Gilad GreenProperty or indexer 'DateTime.Month' cannot be assigned to -- it is read only- user3127554