Find the months in the list using Linq

advertisements

I have list like this

 public class Result
{
    public string id { get; set; }
    public string name { get; set; }
    public string startDate { get; set; } //smaple date 2014-03-31T12:30:03
}

List<Result>

Now I want to get all month names that's inside startDate of this list.And I tried some thing like this

List<string> mnamesList= result.Select(s => Convert.ToDateTime(s.startDate).ToString("MMMM")).ToList();

As you can see this loop will return repeated month names, I don't know how to fetch only different moths using Linq. Can any one point out the correct way?


I think you can use the Linq Distinct() function as follows:

List<string> mnamesList= result.Select(s => Convert.ToDateTime(s.startDate).ToString("MMMM")).Distinct().ToList();