Possible Duplicate:
How to Select Min and Max date values in Linq Query
I’ll start by saying my experience with LINQ is very limited. I have been using nested if statements to find the oldest file of 3, and it works just fine. But I’m trying to expand my use of newer technology. A lot of what I read about LINQ gets way over my head pretty fast. Especially when they start using lambda’s. So I can get the 3 files dates but how can I grab the oldest among them using LINQ? Or is it even possible? I have the psudo code below.
DateTime file1 = File.GetLastWriteTime(@"c:\test1.txt");
DateTime file2 = File.GetLastWriteTime(@"c:\test2.txt");
DateTime file3 = File.GetLastWriteTime(@"c:\test3.txt");
DateTime[] dates = { file1, file2, file3 };
var date = from d in dates
where d is oldest date
select d;
Thanks
is all you need.