I've more than two XML Document (generated through for loop, based on certain criteria) and want to store them in an array (if possible).
For example: XmlDocument[] xmlDoc = {"xmlDoc1", "xmlDoc2"};
Is it possible to do so? If not, any suggestions?
I've more than two XML Document (generated through for loop, based on certain criteria) and want to store them in an array (if possible).
For example: XmlDocument[] xmlDoc = {"xmlDoc1", "xmlDoc2"};
Is it possible to do so? If not, any suggestions?
Is your for loop dynamically generating them?
Populate a List
, then convert that to an array.
using System.Collections.Generic;
using System.Linq;
// ....
List<XmlDocument> l = new List<XmlDocument>();
for(var i = 0; i < loopSize; ++i)
{
XmlDocument doc = GenerateTheDocument(i);
l.Add(doc);
}
XmlDocument[] asArray = l.ToArray();
Do you actually need it in array format? You could just use the List
from then on.