More fun with LINQ
Apr. 20th, 2008 10:47 pmHaving finally gotten back to the stuff I was looking at a couple of weeks ago, I've now discovered that I can replace:
with
Sadly, LINQ doesn't seem to have any way of executing queries rather than returning result sets. But then it is Language INtegrate Query. I think that's about as simple as you can get. Although I could replace the foreach loop with
doggies.ForEach(
dog => dog.Paws.ForEach(
paw => paw.Claws.ForEach(
claw => claw.Clip())));with
var myClaws = from dog in doggies from paw in dog.Paws from claw in paw.Claws select claw;
foreach (Claw claw in myClaws)
{
claw.Clip();
}Sadly, LINQ doesn't seem to have any way of executing queries rather than returning result sets. But then it is Language INtegrate Query. I think that's about as simple as you can get. Although I could replace the foreach loop with
myClaws.ForEach(claw => claw.Clip());if I really wanted to...
no subject
Date: 2008-04-20 10:06 pm (UTC)(from dog in doggies from paw in dog.Paws from claw in paw.Claws select claw).ForEach(claw => claw.Clip());
?
no subject
Date: 2008-04-21 07:59 am (UTC)no subject
Date: 2008-04-21 11:43 am (UTC)no subject
Date: 2008-04-21 11:49 am (UTC)no subject
Date: 2008-04-20 10:21 pm (UTC)no subject
Date: 2008-04-21 12:37 am (UTC)no subject
Date: 2008-04-21 11:47 am (UTC)no subject
Date: 2008-04-21 11:50 am (UTC)It's possibly simpler when it's A[i].B[j].C[k], but not when it's
A[i].B.C.D.E[j].F.G.H.I[k]
especially when there are multiple lines referencing each level.
no subject
Date: 2008-04-21 01:17 am (UTC)no subject
Date: 2008-04-21 08:33 am (UTC)no subject
Date: 2008-04-21 08:45 am (UTC)no subject
Date: 2008-04-21 09:11 am (UTC)no subject
Date: 2008-04-21 09:31 am (UTC)But yes - more of a "look what I can do!" than anything you'd want in real life.