Write below code:-
public int GetNoOfDaysInYear(int Year)
{
int NoOfDays = 0;
if (Year > 0)
{
if (DateTime.IsLeapYear(Year))
NoOfDays = 366;
else
NoOfDays = 365;
}
return NoOfDays;
}
To test above function:-
Response.Write("No of days is :- " + GetNoOfDaysInYear(DateTime.Now.Year) + "<br/>");
Response.Write("No of days is :- " + GetNoOfDaysInYear(2016) + "<br/>");
Response.Write("No of days is :- " + GetNoOfDaysInYear(2017) + "<br/>");
Output:-
No of days is :- 365
No of days is :- 366
No of days is :- 365