C#/Linq : Filter a list based on From/ To dates (and IENUMERABLE to LIST)

1 comment

Filter my List (retur.Tilbudsliste)

based on input of from and to-dates

if (param.FromDato > DateTime.MinValue || param.ToDate > DateTime.MinValue)

{

      //filter on date

      var filtrert =    from t in retur.TilbudsListe

                        where t.DateRegistered >= param.FromDate &&

                             (param.ToDate == DateTime.MinValue || t.DateRegistered <= param.ToDate)

                        select t;

     retur.TilbudsListe = filtrert.ToList();

}

The result filtrert is of type Ienumerable, and is then cast to a list with:

retur.TilbudsListe = filtrert.ToList();

Note that with the check on DateTime.Minvalue we've made both inputs optional,

allowing us to specify none, one or both params.

Posted via email from Henris blogg

1 comment :

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete