Thanks to Linq to objects we can have a more sql like coding style in c#. For somebody that has actual sql knowledge, this comes in very handy.
But it seems that several coding methods perform the same task and gives the same result.
So what coding syntax would you prefer?
For example, assume you want to know which items are given in 2 sets?
You could get this list through following code.
1 |
<span class="kwrd">string</span>[] filesList1 = System.IO.Directory.GetFiles(@"C:\temp\List1?); |
1 |
<span class="kwrd">string</span>[] filesList2 = System.IO.Directory.GetFiles(@"C:\temp\List2?); |
1 |
  |
1 |
var fileListEqual = from file1 <span class="kwrd">in</span> filesList1 |
1 |
join file2 <span class="kwrd">in</span> filesList2 |
1 |
on System.IO.Path.GetFileName(file1) equals System.IO.Path.GetFileName(file2) |
1 |
select System.IO.Path.GetFileName(file1); |
1 |
  |
1 |
var fileListEqual2 = (from fileIpod <span class="kwrd">in</span> filesList1 |
1 |
select System.IO.Path.GetFileName(file1)).Intersect |
1 |
(from fileDisk <span class="kwrd">in</span> filesList2 |
1 |
select System.IO.Path.GetFileName(file2) |
1 |
); |
[Tags].net, linq[/Tags]