I am trying to load multiple elements with the same name from XML into a class using deserialisation in C#. Everything in my example loads fine but the array elements (Element3) are not populated.
Code:
class Program
{
static void Main(string[] args)
{
FileStream file = new FileStream("service.xml", FileMode.Open);
if (file != null)
{
XmlSerializer serializer = new XmlSerializer(typeof(Service));
Service service = (Service)serializer.Deserialize(file);
}
}
}
public class Service
{
public bool Element1;
public string Element2;
public string[] Element3;
}
XML:
<Service>
<Element1>true</Element1>
<Element2>Text 1</Element2>
<Element3>Text 2</Element3>
<Element3>Text 3</Element3>
</Service>