在泛型集合类中使用 IEnumerable (Generic) 接口实现 IEnumerable (Non-generic) 需要什么?
msdn 上的代码示例说明(链接 - http://msdn.microsoft.com/en-us/library/9ekhta0(v=vs.110).aspx)
public class App
{
// Excercise the Iterator and show that it's more
// performant.
public static void Main()
{
TestStreamReaderEnumerable();
TestReadingFile();
}
public static void TestStreamReaderEnumerable()
{
// Check the memory before the iterator is used.
long memoryBefore = GC.GetTotalMemory(true);
// Open a file with the StreamReaderEnumerable and check for a string.
var stringsFound =
from line in new StreamReaderEnumerable(@"c:\\temp\\tempFile.txt")
where line.Contains("string to search for")
select line; …Run Code Online (Sandbox Code Playgroud)