In episode 77 Joel and Jeff were discussing using links instead of a for loop. I looked in Stack Overflow, Google, and Wikipedia but couldn't find any reference to a links construct. The closest thing I could find was a self referencing linked list which would presumably loop indefinitely. Is links a feature of the Links programming language? If not, what was meant by links in this context.
+2
A:
Yes, I'm pretty sure they said LINQ.
In .Net it's a pretty useful feature allowing you essentially "select" items from an object collection using syntax that looks suspiciously like SQL:
List<Person> personList = // maybe passed into a method or whatever
IEnumerable<Person> filteredList = from p in personList
where p.Age > ageThreshold
select p
return filteredList.ToList<Person>();
There's a great Manning book on it: "LINQ in Action" and they have some sample downloadable chapters if you want to learn more.
dustmachine
2010-01-13 22:40:53
+2
A:
I'm sure that they were talking about using LINQ (Language INtegrated Query), not links, to replace foreach
loops.
var stuff = list.Where( l => l.StartsWith( "a" ) ).ToList();
or
var stuff = (from l in list
where l.StartsWith("a")
select l).ToList();
vs
var stuff = new List<string>();
foreach (var item in list)
{
if (item.StartsWith("a"))
{
stuff.Add( a );
}
}
tvanfosson
2010-01-13 22:42:42