Hi guys,
I refactored my foreach loop from this before:
foreach (KeyValuePair[string, string] param in paramsList) {
XmlElement mainNode = xmlDoc.CreateElement("parameter");
mainNode.SetAttribute("name", param.Key);
mainNode.SetAttribute("value", param.Value);
rootNode.AppendChild(mainNode);
}
to this, using LINQ:
XmlElement mainNode = xmlDoc.CreateElement("parameter");
var selected = paramsList.AsEnumerable().Select(param => param).ToList();
selected.ForEach(x => (mainNode.SetAttribute("name", x.Key)));
selected.ForEach(x => (mainNode.SetAttribute("value", x.Value)));
rootNode.AppendChild(mainNode);
However, i know the section below can still be refactored into a single loop but i dont know how. please enlighten me.
selected.ForEach(x => (mainNode.SetAttribute("name", x.Key)));
selected.ForEach(x => (mainNode.SetAttribute("value", x.Value)));