Suppose I have this class:-
public class Availability
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
And a collection based on it:-
List availability = new List
{
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)}
};
{
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 > ??
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.

VulpesPosted Jan 9, 2015, 8:23 AM
VulpesPosted Jan 9, 2015, 8:38 AM
Rahul SinghPosted Jan 9, 2015, 8:31 AM
availability.Select((v,i) => new { Value = v, Index = i})
and it worked.
Thank You.