September 2, 2008 01:09 by
admin
Currently rated 4.0 by 1 people
- Currently 4/5 Stars.
- 1
- 2
- 3
- 4
- 5
August 21, 2008 01:24 by
admin
Glenn Block has an implementation of ForEach for IEnumerable:
1: public static class IEnumerableUtils {
2: public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action) {
3: foreach(T item in collection) {
4: action(item);
5: }
6: }
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
August 21, 2008 01:18 by
admin
Eric White has a post on finding duplicates using LINQ. Here is the sample:
1: int[] listOfItems = new[] { 4, 2, 3, 1, 6, 4, 3 };
2:
3: var duplicates = listOfItems
4: .GroupBy(i => i)
5: .Where(g => g.Count() > 1)
6: .Select(g => g.Key);
7:
8: foreach (var d in duplicates) {
9: Console.WriteLine(d);
10: }
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
July 14, 2008 00:49 by
admin
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
July 14, 2008 00:47 by
admin
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
July 14, 2008 00:46 by
admin
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
May 22, 2008 09:16 by
admin
Well, not really, but The Great LINQ shows a usage of LINQ to Objects over a chemistry domain:
from atom in molecule.Atoms
where atom.Element == Element.Hydrogen
and atom.Bonds.Count == 1
from atom2 in atom.Bonds[0].FindAtom(a => a != atom && a.Element == Element.Oxygen)
where atom2.FindBonds(b => b != atom.Bonds[0]).Count == 1
select atom2.FindBonds(b => b != atom.Bonds[0])[0].FindAtom(a => a != atom2)
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
May 22, 2008 01:06 by
admin
Igor Ostrovsky has a post about 7 tricks to simplify your programs with LINQ.
#1 is pretty cool:
int[] a = Enumerable.Repeat(-1, 10).ToArray();
int[] b = Enumerable.Range(0, 10).ToArray();
int[] c = Enumerable.Range(0, 10).Select(i => 100 + 10 * i).ToArray();
I disagree with #2 - it has serious performance implications. Go check out the link to see them all...
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
May 22, 2008 01:01 by
admin
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
May 22, 2008 00:58 by
admin
In my opinion the let keyword is one of the most power features of LINQ. Stuart Leeks posts about using let in LINQ to objects.
var query = from fileSystemInfo in fileSystemInfos
where fileSystemInfo is FileInfo
let fileInfo = (FileInfo)fileSystemInfo
where fileInfo.Length < 1000
select fileInfo;
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5