Can the below function be improve?(C#3.0)
Posted
by Newbie
on Stack Overflow
See other posts from Stack Overflow
or by Newbie
Published on 2010-06-16T06:51:19Z
Indexed on
2010/06/16
6:52 UTC
Read the original article
Hit count: 199
c#3.0
I have the below function
public static List<DateTime> GetOnlyFridays(DateTime endDate, int weeks, bool isIncludeBaseDate)
{
//Get only the fridays from the date range
List<DateTime> dtlist = new List<DateTime>();
List<DateTime> tempDtlist = (from dtFridays in GetDates(endDate, weeks)
where dtFridays.DayOfWeek == DayOfWeek.Friday
select dtFridays).ToList();
if (isIncludeBaseDate)
{
dtlist = tempDtlist.Skip(1).ToList();
dtlist.Add(endDate);
}
else
{
dtlist = tempDtlist;
}
return dtlist;
}
What basically I am doing is getting the datelist using the GetDates function and then depending on the isIncludeBaseDate bool value
(if true) skipping the last date and adding the Base Date
It is working fine but can this program can be improve?
I am using C#3.0 and Framework 3.5
Thanks
© Stack Overflow or respective owner