簡體   English   中英

如何在 object in.Net Core [on hold] 中創建循環

[英]How to create a loop inside object in .Net Core [on hold]

我正在我的 controller 中創建一個 IActionResult ,它將從我的數據庫中下載一條記錄並將其寫入帶有制表符分隔的文本文件中。 我想在var records = new List<BdoRpt>中放置一個循環,該循環將插入new BdoRpt{ }的每條記錄,但我總是遇到語法錯誤或紅色卷曲下划線。 我怎樣才能在其中制作一個循環。

public IActionResult DownloadList()
        {
            #region download process

            var config = new CsvHelper.Configuration.Configuration();
            config.Delimiter = "\t";

            var records = new List<BdoRpt>
            {
               //when I put this while clause it show some errors.
               //I need to make a loop of records of new BdoRpt {  }
              while (true) 
               {
                new BdoRpt
                {
                    DocDateInDoc = "10/14/2019",
                    DocType = "DZ",
                    CompanyCode = "300",
                    PosDateInDoc = "10/14/2019",
                    FiscalPeriod = "08",
                    CurrentKey = "PHP",
                    RefDocNum = "1471795",
                    DocHeadT = "BPI",
                    PosKeyInNextLine = "40",
                    AccMatNextLine = "11231131",
                    AmountDocCur = "727299.75",
                    ValDate = "10/14/2019",
                    AssignNum = "EEA",
                    ItemText = "1000136212",
                    PosKeyInNextLine2 = "15",
                    AccMatNextLine2 = "1300000093",
                    AmountDocCur2 = "727299.75",
                    BaseDateDueCal = "10/14/2019",
                    ItemText2 = "1000136212"
                }
              }
            };

            using (var writer = new StreamWriter("C:\\file.txt"))
            using (var csv = new CsvWriter(writer, config))
            {
                csv.WriteRecords(records);
            }

            return RedirectToAction(nameof(Lsmw));

            #endregion download process
        }
var records = new List<BdoRpt>();

while (condition) 
{
    records.Add(new BdoRpt() {
        //properties
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM