Of all the new features in VS2007, I would have to rate the LINQ stuff tops! I've put together a small example of using linq on a custom iterator. You can put the following code into a seperate class (I've called it LinqToDisk)
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqStuff
{
class LinqToDisk : IEnumerable<FileInfo>
{
public string Folder
{
get; set;
}
public LinqToDisk() : this(@"C:\") { }
public LinqToDisk(string folder)
{
this.Folder = folder;
}
#region IEnumerable<FileInfo> Members
public IEnumerator<FileInfo> GetEnumerator()
{
foreach (FileInfo fileinfo in (new DirectoryInfo(Folder)).GetFiles())
{
yield return (fileinfo);
}
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
}
}
This custom enumerator can then be used as follows:
var resultSet = from fileInfo in new LinqToDisk() where
fileInfo.FullName.IndexOf(".bat") > 0 select fileInfo.FullName;
foreach (var fileName in resultSet)
{
Console.WriteLine(fileName);
}
As you can see from the query, I've select the FullName property of the FileInfo objects which are returned by the custom enumerator. I'll work on some more practical examples to post shortly.