I'd avoid using XML, something that maintains the link between the XML structure and the information held would look like:
="1.0"
<chromosome>
<gene>7</gene>
<gene>1</gene>
<gene>5</gene>
<gene>0</gene>
</chromosome>
The xml is much bigger than the information it contains and problem becomes worse if you are storing bits/bools rather than ints.
Pesonally, as chromosome information is so basic, you could write directly to disk in csv format.
7,1,5,0
As the CSV format is so simple, I'd do something like this:
public class Chromosome
{
char delimiter = ',';
public List<int> Genes
{
get;
private set;
}
public override ToString()
{
StringBuilder sb = new StringBuilder();
foreach(int gene in Genes)
{
sb.Append(gene);
sb.Append(delimiter);
}
return sb.ToString().Trim(delimiter);
}
public void ReadString(string csv)
{
Genes.Clear();
var items = string.split(delimiter);
foreach (string item in items)
{
Genes.Add(int.Parse(item));
}
}
}
I've not tested the above, but you should get the idea. Then all you need do is write to file if required. Google c# streamreader and c# streamwriter for more info.
One thing about my code is that it leaves the serialization in the class, this is not an ideal solution, so you should separate it out. The other thing you could consider is a
Custom Serializer[
^]