c# - Aggregate sub-lists using LINQ -


I have a list of objects (i.e. integer) and I want to add sub-lists with LINQ.

For example:

Basic list: [1, 4, 5, 3, 4, 10, 4, 12]

Sub-lists: [[1,4,5,3], [4,5,3,4], [5,3,4 , 10], [3, 4, 10,4], [4,10,4,12]

Results (aggregate list): [5, 5, 10, 10, 12]

I want to create a maximum sub-list for the maximum and the following n = 3 elements for each element . Is it possible with LINQ or do I need to create my own aggregation system?

Thank you in advance, Christian

  public INIM rank & lt; IEnumerable & lt; Int & gt; & Gt; GetSubLists (int [] collection) {for (int i = 0; i & lt; collection.Length - 3; i ++) yield returns collection. Skip (i). Take (4); GetSubLists (original). Select (l => L. Max ());   

or in a line

  int [] original = {1, 4, 5, 3, 4, 10, 4, 12}; Int Chuckcon = 4; Enermereble.Range (0, root - chuncount + 1). Select (i = & gt; Original. Skip (i) Take (Chuckcount). Select (L => L. Max ());    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -