Finding if a target number is the sum of two numbers in an array via LINQ and get the and Indices
- by Dr.H
Hello I am new to Linq , I found this thread which explain 90% of what I need
http://stackoverflow.com/questions/2331882?tab=newest#tab-top , thanks "pdr"
but what I need is to get the Indices too , here is my modification I get the index of the first number but I don't know how to get the index of the second number
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var result = from item in numbers.Select((n1, idx) =>
new { n1,idx, shortList = numbers.Take(idx) })
from n2 in item.shortList
where item.n1 + n2 == 7
select new { nx1 = item.n1,index1=item.idx, nx2=n2 };