0

Say I got next sequence:

1 2 3 4 5 6 7 8 9 10 

I need make next thing with Linq:

1,2; 2,3; 3,4; 4,5; ... 9,10; 

Can't get it.

2
  • Why do you need to use LINQ to do this? Commented Oct 25, 2012 at 8:32
  • 'coz it's SQL data. I get it with EF. Commented Oct 25, 2012 at 8:47

3 Answers 3

5

Is this what you want?

 var list = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; var result = Enumerable.Range(0, list.Length - 1) .Select(i => new[] {list[i], list[i + 1]}); 
Sign up to request clarification or add additional context in comments.

Comments

0
your_sequence.Take(high - low).Select(i => new []{i, i + 1}) 

In your case: low = 1, high = 10.

To test you can write

Enumerable.Range(1, 10).Take(10 - 1).Select(i => new []{i, i + 1}) 

in LinqPad

Comments

0
var res = Enumerable.Range(1, n).Select(item => new[] { item, item + 1 }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.