我有两个文件被读入单独的数组,例如:
String[] leaseName2 = new String[1000];
String[] fieldName2 = new String[1000];
String[] reservoir2 = new String[1000];
String[] operator2 = new String[1000];
String[] county2 = new String[1000];
String[] state2 = new String[1000];
String[] majo2 = new String[1000];
String[] resvCatgory2 = new String[1000];
String[] netOil2 = new String[1000];
String[] netGas2 = new String[1000];
String[] netNGL2 = new String[1000];
String[] leaseName = new String[1000];
String[] fieldName = new String[1000];
String[] reservoir = new String[1000];
String[] operator1 = new String[1000];
String[] county = new String[1000];
String[] state = new String[1000];
String[] majo = new String[1000];
String[] resvCatgory = new String[1000];
String[] netOil = new String[1000];
String[] netGas = new String[1000];
String[] netNGL = new String[1000];
然后我使用 Linq 合并这两个文件,以合并两个匹配的数组,例如netOil
和netOil2
给我一个double
答案。有一堆不同的数据行由相同的seqNum
数组匹配。
String[] seqNum2 = new String[1000]; //This will be the identifier
String[] seqNum = new String[1000]; //This will be the identifier
我遇到的问题是使用标识数组输出所有相应的数据,例如leaseName[]
andfieldname[]
和 and 。这是我的 Linq 代码:reservoir[]
seqNum
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 items2.Join(items, i => i.Seq, i => i.Seq, (a, b) => new
{
SeqID = a.Seq,
Answer = this.GetTheAnswer(Convert.ToDouble(a.Oil), Convert.ToDouble(b.Oil)),
//OilNum1 = a.Oil, GIVES FIRST OIL FROM NET OIL ARRAY 1, item.oilnum1 will print out first oil #
//OilNum2 = b.Oil, GIVES SECOND OIL FROM NET OIL ARRAY 2, item.OilNum2 ********
}))
{
sw.WriteLine(item.SeqID + "," + item.Answer); //this prints out the seqNum and Answer that I want to match with all of the other data in the arrays
/* commented out to see what I've tried
int x = listHead;
x.Equals(item.SeqID);
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}, {36}",
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.SeqID, item.Answer);
x = pointers[x];
//sw.WriteLine(item);
}*/
}
sw.Close();
}
}
我无法打印出循环中匹配的所有数据seqNum
,foreach
所以我尝试创建另一个循环,但打印出很多没有用的额外数据。如果有人知道如何seqNum
在我得到Answer
Linq 代码后打印出所有数据,如果你能告诉我,我将不胜感激。任何帮助将不胜感激。