c# - selecting and skipping elements -


I'm trying to improve some code and I think it's not a better way to do what's currently. Essentially I divide the number outside for the numbers that I want to select, within that loop I select the item based on an internal loop of the number of items which I need to make an item , Which is modified from the external lip value, so in the example below the outer loop twice (0,1) and the outer loop per external loop (0,1, 2,3) twice

Can anyone see more readable ways to do this or is there a way to do this without two loops?

Hope that makes sense Thanks.

XML

  string xml = @ " gt; & lt; select & gt; 2 & lt; / select & gt; & lt; itemArray & Gt; & lt; items & gt; one & lt;  gt; & gt; items & gt; two & lt; / item & gt; & lt; items & gt; three & lt; / item & gt; ;  Four    "; Var doc = XDocument.Parse (xml);  

Here the selection value indicates how many items make an "object" so that in this case 2 items are an object (this can be anyone but the number of items will be allowed forever. Right number of items) I am currently not doing anything

  list & lt; List & lt; XElement & gt; & Gt; Item = new list & lt; List & lt; XElement & gt; & Gt; (); For (int i = 0; i  

Items end with a list of inventory, each item contains 2 excelments each (one and two together and three and four together).

  Item one item Two three four  

An easy way to do this is with a single LINQ statement. You can do the following by the group: item index / batchSize :

  int batchSize = (int) doc.Element ("MainItem") element ("select"); var items = doctor. ("Item"). Characteristics ((E, I) => New {i, e}) .GroupBy (G = & gt; G / Batch Size) Select (G = & gt; G. Select (GV = & gt; GVE));  < / Pre> 

This is in the structure you describe in IEnumerable & lt; IEnumerable & lt; XElement & gt; & Gt; returns.


Comments