I need to add a variable number of XElements to my XML document based on the value of e(which is different each time). I think I need to do something similar to what I have below but the below code gives me 6 errors. These are:
- Only assignment, call, increment, decrement, and new object expressions can be used as a statement x 2
- Invalid expression term 'for'/')'/')'
; expected
int e = 3; doc.Root.Add(new XElement(ns + "LineItemList", for(int i = 0; i <= e; i++) { new XElement("ItemNumber", i.ToString()); } ));
What am I doing wrong?
To put my question another way, my understanding is that to have my LineItem elements inside my LineItemListelement, I need to put my LineItem's inside the declaration of LineItemList.
If somebody could tell me how to explicitly open and close elements, instead of them being opened and closed implicitly this would help a lot.