亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.Net CSVHelper 訪問所有記錄

.Net CSVHelper 訪問所有記錄

C#
HUH函數 2022-10-23 15:42:06
我對如何訪問所有記錄有點困惑。它不會讓我通過項目運行 foreach() 并且它只返回第一個作為對象。我知道它在文檔中這么說。但我不知道該怎么辦。The GetRecords<T> method will return an IEnumerable<T> that will yield records. What this means is that only a single record is returned at a time as you iterate the records. That also means that only a small portion of the file is read into memory. Be careful though. If you do anything that executes a LINQ projection, such as calling .ToList(), the entire file will be read into memory. CsvReader is forward only, so if you want to run any LINQ queries against your data, you'll have to pull the whole file into memory. Just know that is what you're doing.這是我的代碼protected void WatcherCreated(object sender, FileSystemEventArgs e)    {        Console.WriteLine("Watcher Created");        string[] files = Directory.GetFiles(_watchedFolder, "*.csv");        foreach (string file in files)        {            using (var reader = new StreamReader(file))            using (var csv = new CsvReader(reader))            {                try                {                    csv.Read();                    var records = csv.GetRecord<InputCsv>();                }                catch (CsvHelper.HeaderValidationException exception)                {                    Console.WriteLine(exception);                    throw;                }            }        }    }記錄是假定的 IEnumerable .. 我最終想使用對象 o 使用 Newtonsoft.Json 將其解析為 json在 csv.GetRecords(); 之后,它甚至沒有為我提供 .ToList() 選項。
查看完整描述

1 回答

?
侃侃爾雅

TA貢獻1801條經驗 獲得超16個贊

您在函數調用中缺少一個字母:

var records = csv.GetRecord<InputCsv>();

你應該打電話GetRecords- 注意額外的 s。

var records = csv.GetRecords<InputCsv>();


查看完整回答
反對 回復 2022-10-23
  • 1 回答
  • 0 關注
  • 103 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號