日期:2014-05-18  浏览次数:21171 次

新手问题。Error: Type and identifier are both required in a foreach statement
class Program
  {
  static void Main(string[] args)
  {
  XmlImplementation objXImp = new XmlImplementation();
  XmlDocument objXDoc = objXImp.CreateDocument();

  XmlNodeList myNodeList = objXDoc.GetElementsByTagName("name");
  XmlNode node;

  //iterate through XmlNodeList
  foreach(node in myNodeList)
  {
  Console.WriteLine(node.Name = "in" + node.NamespaceURI + "\n");
  //Next node
   
  }
  }
  }
错误如题,提示问题出在in上面,是foreach的使用错误,但是我不知道错在哪里!

------解决方案--------------------
XmlNode node; 

//iterate through XmlNodeList 
foreach(node in myNodeList) 

Console.WriteLine(node.Name = "in" + node.NamespaceURI + "\n"); 
//Next node 

}

改:
--->

//iterate through XmlNodeList 
foreach(XmlNode node in myNodeList) 

Console.WriteLine(node.Name = "in" + node.NamespaceURI + "\n"); 
//Next node 

}
------解决方案--------------------
......
foreach写错了吧,应该是:
foreach(XmlNode node in myNodeList)