XMLに保存する方法

LINQ to XMLを使う場合、

var xml = new XDocument(
	new XDeclaration("1.0","utf-8", "true"),
	new XComment( "4th grade science "),
	new XElement ( "sciencedata",
	new XElement("iDaqNum", GlobalConst.iDaqNum),
	new XElement("clrOddColor",
		new XElement("r",GlobalConst.clrOddColor.R),
		new XElement("g",GlobalConst.clrOddColor.G),
		new XElement("b",GlobalConst.clrOddColor.B)
	),
	new XElement("clrTxtDaqtm",
		new XElement("r",GlobalConst.clrTxtDaqtm.R),
		new XElement("g",GlobalConst.clrTxtDaqtm.G),
		new XElement("b", GlobalConst.clrTxtDaqtm.B)							
	),
	new XElement("iGroupNum", GlobalConst.iGroupNum),
        new XElement("iTxtBoxHeight", GlobalConst.iTxtBoxHeight),
	new XElement("iTxtBoxWidth", GlobalConst.iTxtBoxWidth),
	new XElement("iTxtDaqtmWidth", GlobalConst.iTxtDaqtmWidth)
	)
);
xml.Save(sf.FileName);

としてあげると、自動的にXMLを作ってくれるので便利。
でも、配列のデータを順次入れてあげる方法が不明だったので、
↑の方法は使わず自前でXMLをごりごり書いてあげてもOK。
エンコーディングutf-8以外は確かめていないので他は不明.

string szXML;
				szXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
				szXML += "<sciencedata>\r\n";
				szXML += "\t<iDaqNum>"+GlobalConst.iDaqNum+"</iDaqNum>\r\n";
				szXML += "\t<clrOddColor>\r\n\t\t<r>"+GlobalConst.clrOddColor.R+"</r>\r\n\t\t<g>"+GlobalConst.clrOddColor.G+"</g>\r\n\t\t<b>"+GlobalConst.clrOddColor.B+"</b>\r\n\t</clrOddColor>\r\n";
				szXML += "\t<clrTxtDaqtm>\r\n\t\t<r>"+GlobalConst.clrTxtDaqtm.R+"</r>\r\n\t\t<g>"+GlobalConst.clrTxtDaqtm.G+"</g>\r\n\t\t<b>"+GlobalConst.clrTxtDaqtm.B+"</b>\r\n\t</clrTxtDaqtm>\r\n";
				szXML += "\t<iGroupNum>"+GlobalConst.iGroupNum+"</iGroupNum>\r\n";
				szXML += "\t<iTxtBoxHeight>"+GlobalConst.iTxtBoxHeight+"</iTxtBoxHeight>\r\n";
				szXML += "\t<iTxtBoxWidth>"+GlobalConst.iTxtBoxWidth+"</iTxtBoxWidth>\r\n";
				szXML += "\t<iTxtDaqtmWidth>"+GlobalConst.iTxtDaqtmWidth+"</iTxtDaqtmWidth>\r\n";
				//時間間隔
				szXML += "\t<dataDaqtm>\r\n";
				for ( int i = 0; i < txtDaqtm.Length;i++) {
					szXML += "\t\t<d_"+i+">"+txtDaqtm[i].Text+"</d_"+i+">\r\n";
				}
				szXML += "\t</dataDaqtm>\r\n";
				
				//実際のデータ
				szXML += "\t<temperature>\r\n";
				for (int i = 0; i < GlobalConst.iDaqNum; i++) {
					for (int j = 0; j < 10; j++){
						szXML += "\t\t<d_"+i+"x"+j+">"+txtGroupData[i,j].Text.Trim()+"</d_"+i+"x"+j+">\r\n";
					}
				}
				szXML += "\t</temperature>\r\n";
				


				szXML += "</sciencedata>\r\n";

				sw.Flush();
				sw.Write(szXML);
				sw.Close();

こういうのでXML出力してもC#は後で読み込むときに理解してくれる。