Rahul Singh

Rahul Singh

  • NA
  • 1.4k
  • 579.4k

How to access last element value in query syntax?

Jan 9 2015 7:58 AM
Suppose I have this class:-
 
public class Availability
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }
 
And a collection based on it:-
 
List<Availability> availability = new List<Availability>
{
      new Availability { StartDate = new DateTime(2015,1,5), EndDate = new DateTime(2015,1,10)},
      new Availability { StartDate = new DateTime(2015,1,15), EndDate = new DateTime(2015,1,20)},
      new Availability { StartDate = new DateTime(2015,1,22), EndDate = new DateTime(2015,1,28)}
};
 
Now, I am trying to write some query,(that query is very big
but I need help for particulat scenario)
 
var result = //Other query
             from a in availability
             where d < a.StartDate && d > ??
 
At "??" I want to access EndDate of last accessed list i.e. when query
is running for first object (05/Jan, 10/Jan) since it is first object
in collection I don't have any filter but when query is executing
second object i.e (15/Jan, 20/Jan) I want to access 10/Jan (EndDate
of last accessed object. But, `a` will currently hold the object with
date (15/Jan, 20/Jan) How to access previous one? I hope I am clear.
 
 
 

 

 

Answers (3)