C# - Checking Index values of two sets
From two sets
var set1 =new int[] { 1, 2, 3 开发者_如何学编程};
var set2 =new int[] { 100, 200, 300 };
How to check index value of elements in set1 and set 2 ? if index value of elements of set1 equals to index value of elements of set2 then i want that pair like
{1,100} ,{2,200},{3,300}.
Some incomplete code
var pairs=from n1 in set1
from n2 in (from num in set2 where ((num1,index)=> );
For example you can do:
var pairs=
set1.Select((item, index) => new
{
n1= item, n2= set2[index]
}).ToArray();
Or if set2 does not have an indexer, get n2 as follows:
n2 = set2.Skip(index).Take(1).Single()
Have a look at this
int[] set1 = {1, 2, 3};
int[] set2 = {100, 200, 300};
var t = from i1 in set1
from i2 in set2
where Array.IndexOf(set1, i1) == Array.IndexOf(set2, i2)
select new int[] { i1, i2 };
I am assuming you just want to join these two arrays. This is how I would do it
var pairs=from n1 in set1
from n2 in set2
select new
{
n1,
n2
}
This will return both sets combined. This is assuming both sets are already sorted.
精彩评论