C
On the one hand, you might think that interfaces initiated in the cycle foreach and the idea cannot be unpropriized (and that's true). But on the other hand, the compiler can't know exactly what's in the variable. intf there's something to irritate by foreach (in other words, he does not know if the cycle will be implemented at least once). It turns out there's a situation where your variable is possible. interfaces I'm gonna stay uninitiated, and that's why the compiler signals the error. In fact, the theoretical developers of the compilator could have had a breathing and compiling compiler to analyse such designs and predict the behaviour of the cycle (when it is obvious to a person, the compiler could have understood it even better), but they probably did not complicate themselves and the compilator of the work and simply forced him to give a report on the protection, including in such an obvious situation.public static void Create_Interfaces()
{
var interfaces = new XDocument(new XElement("Interfaces",
new XElement("Interface",
new XElement("vlan-tagging", XElement.EmptySequence),
new XElement("unit",
new XElement("vlan-id", "10"),
new XElement("family",
new XElement("inet",
new XElement("address",
new XElement("name", "10.10.1.23/24")))))))); ;
var intf = new List<string> { "em0", "em1", "em2" };
foreach (var i in intf)
interfaces.Element("Interfaces").Element("Interface").AddFirst(new XElement("name", i));
interfaces.Save("Interfaces.xml");
}