D
DamienS
G'day LINQ junkies,
I have an array of objects. I need to sort them via a date property
and then, given a particular object, find the object in sequence
before it (or null if it's the first in sequence).
I think that I can use the elementAt method... but don't know how to
find the element that I've selected.
Can someone please fill in the gap? Below is a simple console app that
I'm using to play with it.
Thanks very much in advance,
Damien
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ_walkthrough_order
{
class Program
{
static void Main(string[] args)
{
WalkLinq();
}
public static void WalkLinq()
{
List<clsDate> dates = new List<clsDate>
{
new clsDate(new DateTime(2008,11,1)),
new clsDate(new DateTime(2008,10,1)),
new clsDate(new DateTime(2008,9,1)),
new clsDate(new DateTime(2008,8,1))
};
clsDate d1 = dates[2];
Console.WriteLine(d1.d.ToShortDateString());
//dates.OrderByDescending(x=>x.d).
// .... WHAT NOW?
Console.ReadLine();
}
}
public class clsDate
{
public DateTime d;
public clsDate(DateTime _d)
{
d = _d;
}
}
}
I have an array of objects. I need to sort them via a date property
and then, given a particular object, find the object in sequence
before it (or null if it's the first in sequence).
I think that I can use the elementAt method... but don't know how to
find the element that I've selected.
Can someone please fill in the gap? Below is a simple console app that
I'm using to play with it.
Thanks very much in advance,
Damien
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ_walkthrough_order
{
class Program
{
static void Main(string[] args)
{
WalkLinq();
}
public static void WalkLinq()
{
List<clsDate> dates = new List<clsDate>
{
new clsDate(new DateTime(2008,11,1)),
new clsDate(new DateTime(2008,10,1)),
new clsDate(new DateTime(2008,9,1)),
new clsDate(new DateTime(2008,8,1))
};
clsDate d1 = dates[2];
Console.WriteLine(d1.d.ToShortDateString());
//dates.OrderByDescending(x=>x.d).
// .... WHAT NOW?
Console.ReadLine();
}
}
public class clsDate
{
public DateTime d;
public clsDate(DateTime _d)
{
d = _d;
}
}
}