首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

新手有关问题。Error: Type and identifier are both required in a foreach statement

2012-02-10 
新手问题。Error: Type and identifier are both required in a foreach statementclass Program{static vo

新手问题。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)

热点排行