You can group by month and take the first or last or something else (you did not tell us):
var news = News()
.GroupBy(n => n.Month)
.Select(grp => grp.Last());
Change . From the commentary on Habib’s answer, I see that you want 12 months, even if there is no news. Then you need to do "Linq Outer-Join":
var monthlyNews = from m in Enumerable.Range(1, 12)
join n in News() on m equals n.Month into m_n
from n in m_n.DefaultIfEmpty()
group n by m into MonthGroups
select new {
Month = MonthGroups.Key,
LastNews = MonthGroups.Last()
};
foreach (var m in monthlyNews)
{
int month = m.Month;
var lastNewsInMonth = m.LastNews;
if (lastNewsInMonth != null) ;
}
. , , . :
var monthlyNews = from m in Enumerable.Range(1, 12)
join n in news on m equals n.Month into m_n
from n in m_n.DefaultIfEmpty()
group n by m into MonthGroups
select MonthGroups.Last();
, 12 , null, .