I am trying to run a web application with a TreeView control in Visual Studio 2008 and I get t开发者_开发技巧his error:
'TreeNodeCollection' is an ambiguous reference between 'System.Web.UI.WebControls.TreeNodeCollection' and 'Microsoft.Web.UI.WebControls.TreeNodeCollection'
Can anyone help me?
Well if you know which namespace is the one you want to be using for the node collection, just put the full namespace in front of the TreeNodeCollection object, like such:
Microsoft.Web.UI.Controls.TreeNodeCollection myNodeCollection = new Microsoft.Web.UI.Controls.TreeNodeCollection();
You have references (usings) to two libraries "System.Web.UI.WebControls" and "Microsoft.Web.UI.WebControls". Each of them has class TreeNodeCollection. To resolve problem you have to specify full reference in code:
System.Web.UI.WebControls.TreeNodeCollection collection = null;
Or you can specify aliases to this libraries:
using MWC = Microsoft.Web.UI.WebControls;
using SWC = System.Web.UI.WebControls;
SWC.TreeNodeCollection collection = null;
精彩评论