0

我编写了一些代码,通过调用的标识符匹配两个数组,seqNum并从一些数学中得到答案。我能够打印出我得到的seqNum和 ,Answer但我无法获取 . 随附的所有其他信息seqNum。我希望能够输出这样的东西:

Name Date `seqNum` Answer... 

seqNum我的代码给了我答案,但它只是用不同的 s 和s一遍又一遍地吐出文件中的第一个 Name Answer

这是代码:

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)) 

            }))

            {
                int x = 0;
                x.Equals(item.SeqID);
                while (x != -1)
                {
                    sw.WriteLine(leaseName[x] + "," + item.SeqID + "," + item.Answer);
                    x--;
                }

所以基本上我只需要用正确的seqNumand打印出匹配的名称Answer。如果有人有任何想法或意见,将不胜感激。如果有人需要看,我的数学方法非常简单:

public double GetTheAnswer(double first, double second)
{
    double answer = (first - second) / second;
    return answer;
}
4

2 回答 2

1

好吧,您应该将数据包含在匿名类型中

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)),
        Name = a.Name, // b.Name?
        Date = a.Date, // b ?
        seqNum  = a.seqNum // b ?
   }))

您在 ( while) 内部循环尝试什么foreach?您遍历一组没有重复数据的匿名类型,item只是一组平面数据。

所以之后的一切int x = 0;都是无用的。只需将你在匿名类型中收集的数据逐行输出即可。由于标题(“租赁名称,字段名称,水库,操作员,...)要长得多,我认为该部分应该有更多new { ... }

于 2013-06-10T18:49:21.967 回答
0

您需要更改 x 的分配,因为您没有赋予它任何价值。

int x = Convert.ToInt32(item.SeqID);

尝试一下,看看你是否会得到不同的结果。

于 2013-06-10T16:40:34.893 回答