FILTER OBJECTS INSIDE MODEL CLASS BY DATE

john rob

Total Post:108

Points:756
Posted by  john rob
C# 
C#
 850  View(s)
Ratings:
Rate this:

I have a model object called EventListingResponse like this

 

public class EventListingResponse

{

    public List<events> result { get; set; }

    public int totalResults { get; set; }

}

 public class events

{

    public string id { get; set; }

    public string name { get; set; }

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

}

And I am storing data in this object like this

 

EventListingResponse eventListResponse = rGetAllEventList();//data from another function.

Now I want to filter this list so that I can get a list of events like , -->events from January -->Events from February etc. Can any one point out a good method to accomplish this?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Filter objects inside model class by date

    Hi John, 


    try this:

    var filtered = from item in eventListResponse.result

                   where DateTime.Parse(item.startDate) >= DateTime.Parse("your starting date")

                   and DateTime.Parse(item.startDate) <= DateTime.Parse("your ending date")

                   select item;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!