Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad XML data to array
    primarykey
    data
    text
    <p>I might have a simple question but I just can't figure it out. First I've saved data to a XML file, using this <a href="http://www.blackwasp.co.uk/XMLArrays.aspx" rel="nofollow">Source</a>. First class:</p> <pre><code>public class Employees { public string Name { get; set; } public Employees() { } public Employees(string name) { Name = name; } } public class group { public string Name { get; set; } public List&lt;Employees&gt; Employees { get; set; } public group() { Employees = new List&lt;Employees&gt;(); } </code></pre> <p>Saving XML data in another class.</p> <pre><code> public class SaveXML { static public void SaveData(group info) { XmlSerializer xs = new XmlSerializer(info.GetType()); StreamWriter writer = new StreamWriter("dataArray.xml"); xs.Serialize(writer, info); writer.Close(); } } </code></pre> <p>Form1:</p> <pre><code> private void SaveButton_Click(object sender, EventArgs e) { string[] employees = new string[EmployList.Items.Count]; for (int x = 0; x &lt; EmployList.Items.Count; x++) { employees[x] = EmployList.Items[x].ToString(); } try { group groups = new group(); groups.Name = GroupText.Text; for (int x = 0; x &lt; employees.Length; x++) { groups.Employees.Add(new Employees(employees[x])); } SaveXML.SaveData(groups); } catch (Exception es) { MessageBox.Show(es.Message); } } </code></pre> <p>Now I want to load this data into a array, Here is my class for loading data:</p> <pre><code>public class LoadXML { static public void LoadData(group LoadInfo) { XmlSerializer xs = new XmlSerializer(LoadInfo.GetType()); TextReader Read = new StreamReader("dataxml.xml"); List&lt;Employees&gt; GroupList; GroupList = (List&lt;Employees&gt;)xs.Deserialize(Read); } } </code></pre> <p>This is what I've tried, but it gives me errors:</p> <pre><code> private void LoadButton_Click(object sender, EventArgs e) { group groups = new group(); LoadXML Loading = new LoadXML(); Loading.LoadData(groups); string[] array = new string[10]; array = groups.Employees.ToArray; //error line } </code></pre> <p>So now my question is how to get the GroupList into a Array in the main function. I want to have it in a array because I think it's easier to get a single name out of a array, but on the other hand, the length of the array depends on user input.</p> <p>This is a test program, not the actual program I'm using, this is just to learn it and then implement it in my original project.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload