C#将多条记录写入一行

C#将多条记录写入一行,c#,C#,我正在使用c#编写并创建一个文本文件。我正试图在文本文件的一行上写入两条记录。我的数据源来自存储过程的结果集 这是我的代码。目前我只写了一个又一个记录。我想在一行上写两条记录到一个文本文件中 例如: 记录1记录6 记录2记录7 记录3记录8 记录4记录9 记录5记录10 记录11记录16 记录12记录17 记录13记录18 记录14记录19 记录15记录20 public bool SalesPriceIndexProcess() { int page = 1,

我正在使用c#编写并创建一个文本文件。我正试图在文本文件的一行上写入两条记录。我的数据源来自存储过程的结果集

这是我的代码。目前我只写了一个又一个记录。我想在一行上写两条记录到一个文本文件中

例如:

记录1记录6

记录2记录7

记录3记录8

记录4记录9

记录5记录10

记录11记录16

记录12记录17

记录13记录18

记录14记录19

记录15记录20

    public bool SalesPriceIndexProcess()
    {
        int page = 1, count = 1;
        FileStream fs = new FileStream(Properties.Settings.Default.Path + SalesPriceDirectoryReportName, FileMode.Create);
        StreamWriter sw = new StreamWriter(fs);
        foreach (ManhattanLUSESalesPriceIndex_Result s in _db.ManhattanLUSESalesPriceIndex())
        {
            if (count == 1)
            {
                SalesPriceHeaderWrite(s.BldgClassCd, ref fs, ref sw);
            }
            string saleDate = s.SaleDt.ToString();
            sw.WriteLine("{0,13:C0}{1,-5} {2,-4} {3,5} {4,3} {5,15:C0}{6} {7,-8} {8,4}"
                , s.SalePriceAmt, s.MultiSplitCd
                , Convert.ToInt16(s.StoriesNbr) + s.LandUseMajorCd
                , (s.LegalBlkId + "-"), s.LegalLot
                , s.TransAssdTotalAmt, s.BldgClassCd.PadRight(2)
                , (saleDate.Length > 6 ? saleDate.Substring(4, 2) + "/" + saleDate.Substring(6, 2) + "/" + saleDate.Substring(2, 2) : "")
                , page    
                );

            PclIdPageIndexDict.Add(s.PclId, page);
            if (count % 5 == 0)
            {
                sw.WriteLine(SalesPriceLineBreak);
            }
            if (count % 145 == 0)
            {
                sw.WriteLine(SalesPricePageBreak);
            }

            count++; //increment by 1
            page = count % 145;
        }
        return true;

您需要在队列中存储最后5行。在写下你的台词时,你需要说:

while(!eof) {
  for (int i=0; i<5; i++) {
    queue.enqueue(readline());
  }

  for (int i=0; i<5; i++) {
   write(queue.dequeue());
   write(readline());
   write('\n');
  }
}
while(!eof){
对于(int i=0;i
if(_db.manhattanlusesalepriceindex().Count()<5)
{
//扔
}
其他的
{
var collectionStore=_db.manhattanlusesalepriceindex().ToList();
对于(int i=5;i

编辑的代码

如何将数据集中的两条记录写入同一行的文本文件中?实际上两者都是。我对c#相当陌生,所以解释语法很有帮助。抱歉,我没有检查语法就写了,我的语言错了。更新了我的帖子以帮助您。
if(_db.ManhattanLUSESalesPriceIndex().Count() < 5)
{
// throw
}
else
{
    var collectionStore = _db.ManhattanLUSESalesPriceIndex().ToList();
    for(int i = 5; i < collectionStore.Count(); i++)
    {
        var recordN = collectionStore[i-5];
        // do whatever outputting you want
        var recordNPlusFive = collectionStore[i];
        // do whatever outputting you want
        }
    }
}