Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To keep things simple, I would use the <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx" rel="nofollow">serializer</a> class to do it:</p> <p>Here is the example Config classes:</p> <pre><code>[Serializable] public class Config { public int ValueOne { get; set; } public string ValueTwo { get; set; } public int[] LotsOfValues { get; set; } public List&lt;FurtherConfig&gt; Other { get; set; } } [Serializable] public class FurtherConfig { public int Value { get; set; } } </code></pre> <p>And here is some example usage:</p> <pre><code>var config = new Config { ValueOne = 23, ValueTwo = "Second Value", LotsOfValues = new[] { 23, 34, 34 }, Other = new List&lt;FurtherConfig&gt; { new FurtherConfig { Value = 567}, new FurtherConfig { Value = 98 } } }; var serializer = new XmlSerializer(typeof(Config)); //write out to file using (var fw = File.OpenWrite("config.xml")) serializer.Serialize(fw, config); //read in from file Config newConfig; using (var fr = File.OpenRead("config.xml")) newConfig = serializer.Deserialize(fr) as Config; Console.WriteLine(newConfig.Other[1].Value); //prints 98 </code></pre> <p>This is the serialized output:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;ValueOne&gt;23&lt;/ValueOne&gt; &lt;ValueTwo&gt;Second Value&lt;/ValueTwo&gt; &lt;LotsOfValues&gt; &lt;int&gt;23&lt;/int&gt; &lt;int&gt;34&lt;/int&gt; &lt;int&gt;34&lt;/int&gt; &lt;/LotsOfValues&gt; &lt;Other&gt; &lt;FurtherConfig&gt; &lt;Value&gt;567&lt;/Value&gt; &lt;/FurtherConfig&gt; &lt;FurtherConfig&gt; &lt;Value&gt;98&lt;/Value&gt; &lt;/FurtherConfig&gt; &lt;/Other&gt; &lt;/Config&gt; </code></pre>
 

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