1

我一直在开发一个程序,该程序通过一个名为“SeqID”的标识符连接两个数组并将答案输出到 CSV 文件。

每当我将此答案输出到文件时,它会为一堆行打印出相同的答案,然后最终移动到下一个答案并为一堆行打印出来,依此类推。我认为循环中可能存在问题,但我没有看到。这是代码...

    private void executeBtn_Click(object sender, EventArgs e)
    {
        //NET OIL VARIANCE MATHEMATICS
        if (netOilRadBtn.Checked)
        {
            using (var sw = new StreamWriter("testNetOil.csv"))
            {
                var items = netOil.Zip(seqNum, (oil, seq) => new { Oil = oil, Seq = seq });
                var items2 = netOil2.Zip(seqNum2, (oil, seq) => new { Oil = oil, Seq = seq });
                sw.WriteLine("Lease Name, Field Name, Reservoir, Operator, County, ST, Majo, Resv Cat, Discount Rate, Net Oil Interest, Net Gas Interest, Working Interest, Gross Wells, Ultimate Oil, Ultimate Gas, Gross Oil, Gross NGL, Gross Gas, Net Oil, Net Gas, Net NGL, Revenue To Int., Oper. Expense, Total Invest., Revenue Oil, Revenue Gas, Operating Profit, Revenue NGL, Disc Net Income, SEQ, Well ID, INC ASN, Life Years, Own Qual, Production Tax, NET OIL VARIANCE");

                foreach (var item in items.Join(items2, i => i.Seq, i => i.Seq, (a, b) => new
                {SeqID = a.Seq, Answer = this.GetTheAnswer(Convert.ToDouble(a.Oil), Convert.ToDouble(b.Oil)) 

                }))

                {
                    foreach (var s in item.SeqID)
                    {
                        sw.WriteLine(item.Answer);
                    }

基本上,我希望这段代码实现的只是为两个不同数组中匹配的 seqNum打印一个答案。

4

1 回答 1

2

In

foreach (var s in item.SeqID)

you loop through each char in SeqID. I can't imagine that's useful. Just remove the loop and only do sw.WriteLine(item.Answer).

于 2013-06-10T14:53:12.297 回答