Note that there are some explanatory texts on larger screens.

plurals
  1. POOutputting with LINQ
    primarykey
    data
    text
    <p>I wrote some code that combines two different files onto one file and then it compares the data from the matching seqNum and does a little math equation on them. The problem I am having is printing out all of the other match data with each seqNum with the answer I got from the from the math part. I used LINQ to match the two different seqNum arrays and then wrote a while loop to print out all the data. When every I put an int value on the variable "item"(the answer from the math equation) I get an Out of Bounds Exception, but when I don't put an int value on "item" it loops and outputs the same answer for every item I have in the array then moves on to the next answer and does the same thing. Here's the code...</p> <pre><code> 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) =&gt; new { Oil = oil, Seq = seq }); var items2 = netOil2.Zip(seqNum2, (oil, seq) =&gt; 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 =&gt; i.Seq, i =&gt; i.Seq, (a, b) =&gt; { double first = Convert.ToDouble(a.Oil); double second = Convert.ToDouble(b.Oil); double answer = (first - second) / second; return string.Format("{0}, {1}", a.Seq, answer); })) { int x = listHead; while (x != -1) { sw.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}", QuoteString(leaseName[x]), fieldName[x], QuoteString2(reservoir[x]), operator1[x], county[x], state[x], majo[x], resvCatgory[x], disRate[x], netOil2Int[x], netGas2Int[x], workingInt[x], grossWells[x] , ultOil[x], ultGas[x], grossOil[x], grossNGL[x], grossGas[x], netOil[x], netGas[x], netNGL[x], revToInt[x], operExpense[x], totInvest[x], revOil[x], revGas[x], operatingProfit[x], revNGL[x], discNetIncome[x], seqNum[x], wellID[x], incASN[x], lifeYears[x], ownQual[x], prodTax[x], item[x]); x = pointers[x]; //sw.WriteLine(item); } sw.Close(); } } } </code></pre> <p>I was just wondering if anyone could help me with this problem and just have the answer outputting to the correct seqNum with all the other matching data arrays. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload