0

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?

YWah
  • 571
  • 13
  • 38

1 Answers1

2

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.

Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205
  • Hi @Andrew Shepherd, the xmldocument is dynamically generated through the loop. I want to keep them as xmldocument to the end. – YWah Dec 08 '15 at 02:27