我编写了一些代码,通过名为seqNum
的标识符匹配两个数组,并从一些数学中得到答案。我可以打印出seqNum
和Answer
,但我无法获取seqNum
附带的所有其他信息。我希望能够输出这样的东西:
Name Date `seqNum` Answer...
我的代码给了我答案但是它只是用不同的seqNum
和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--;
}
所以基本上我只需要用正确的seqNum
和Answer
打印出匹配的名称。如果有人有任何想法或意见,那将非常感激。如果有人需要看,我的数学方法非常简单:
public double GetTheAnswer(double first, double second)
{
double answer = (first - second) / second;
return answer;
}
答案 0 :(得分: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 { ... }
部分应该有更多内容。
答案 1 :(得分:0)
您需要更改x的分配,因为您没有给它任何值。
int x = Convert.ToInt32(item.SeqID);
尝试一下,看看你是否得到不同的结果。