Home > Backend Development > PHP Tutorial > Detailed explanation of using iterator to traverse file information_PHP tutorial

Detailed explanation of using iterator to traverse file information_PHP tutorial

WBOY
Release: 2016-07-21 15:07:28
Original
1497 people have browsed it

1. Iterate the lines of the file

Copy the code The code is as follows:

public static IEnumerable ReadLines(string fileName)
{
using (TextReader reader = File.OpenText(fileName))
{
string line;
if (( line = reader.ReadLine()) != null)
                                                                                                                                                                  static void Main()
{
foreach (string line in Iterator.ReadLines(" "))
                                                                                                                                                                                                                                                 Console.WriteLine. proceed Filter




Copy code

The code is as follows:

public static IEnumerable where(IEnumerable predicate)
{ if (source == null || predicate == null)
{
throw new ArgumentNullException();
        }                                                                                                              WhereImplemeter(source, predicate); } private static IEnumerable WhereImplemeter(IEnumerable source, Predicate predicate) foreach (T item in source )
                                                                                                       
                                                                                                                                                                                 
IEnumerable lines = File.ReadAllLines(@"your file name");
Predicate predicate = delegate(string line)
return line .StartsWith("using" );
                                                                          🎜>
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327537.htmlTechArticle1. The line copy code of the iterated file is as follows: public static IEnumerablestring ReadLines(string fileName) { using (TextReader reader = File.OpenText(fileName)) { string line; if (...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template