Tuple<int, double>[] obs1;
Tuple<int, double>[] obs2;
What I'd like to do is create Tuple<int, double>[] obs3
which contains those Tuple<int,double>
which have the same int
in both obs1
and obs2
and then set the corresponding double as:
obs3[i].Item2 = obs1[i].Item2 + obs2[i].Item2
I tried finding the relevant Tuples this way:
var obs3 = from o in obs1 where obs2.Contains(o) select o;
But then I don't know how to access and use the Item2 double
, instead I just get a subset of obs1
.
I keep getting downmarked for my questions.I'm hoping its because I've not tried presenting a first try at a solution.
You can join both arrays on Item1
var query = from t1 in obs1
join t2 in obs2 on t1.Item1 equals t2.Item1
select Tuple.Create(t1.Item1, t1.Item2 + t2.Item2);
Tuple<int, double>[] obs3 = query.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With