国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

asp. net下使用foreach簡(jiǎn)化文本文件的訪問。

2024-07-10 12:40:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
       很多時(shí)候,我們總是按照行的方式訪問文本文件,使用foreach語(yǔ)句能夠極大地簡(jiǎn)化訪問邏輯:例如: 
foreach (string line in new LineReader(”c:/abc.txt”)) 
  Console.WriteLine(line); 
完整代碼如下: 
using System; 
using System.IO; 
using System.Text; 
using System.Collections; 
namespace Forks.Utils.IO 

    public struct LineReader : IDisposable 
    { 
    public LineReader(string file, Encoding encoding) : this(file, encoding, false) 
        { 
    } 
    public LineReader(string file, Encoding encoding, bool ignoreBlankLines) : this(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read), encoding, ignoreBlankLines) 
    { 
    } 
    public LineReader(Stream stream, Encoding encoding) : this(stream, encoding, false) 
    { 
    } 
    public LineReader(Stream stream, Encoding encoding, bool ignoreBlankLines) : this(new StreamReader(stream, encoding), ignoreBlankLines) 
    { 
    } 
    public LineReader(TextReader reader) : this(reader, false) 
    { 
    } 
    TextReader mReader; 
    bool mIgnoreBlankLines; 
    public LineReader(TextReader reader, bool ignoreBlankLines) 
    { 
      mReader = reader; 
      mIgnoreBlankLines = ignoreBlankLines; 
      mCurrent = null; 
    } 
    public LineReader GetEnumerator() 
    { 
      return this; 
    } 
    public void Reset() 
    { 
      throw new NotSupportedException("LineReaderÖ»ÄܶÁȡһ´Î"); 
    } 
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜黄县| 正安县| 隆子县| 卢龙县| 河南省| 象山县| 美姑县| 合山市| 乳源| 万山特区| 卫辉市| 沙洋县| 莱芜市| 郁南县| 墨竹工卡县| 图们市| 吉安市| 台州市| 无为县| 化德县| 奎屯市| 宝鸡市| 安达市| 大宁县| 蓝田县| 观塘区| 邓州市| 洪洞县| 溧水县| 合肥市| 鱼台县| 新丰县| 正安县| 万年县| 容城县| 五华县| 凭祥市| 古浪县| 沈丘县| 安岳县| 米易县|