错误:成员名称在其封闭类型中不能相同

时间:2015-06-07 21:59:30

标签: asp.net-4.5

我使用ASP.NET4.5和visual studio 2013来创建示例应用程序Wingtip Toys。但是当试图显示数据项和细节时,它显示了最后一行代码中的错误,这是 -  protected global :: System.Web.UI.WebControls.ListView ProductList;

  

ProductList:成员名称的封闭类型不能相同。

namespace WingtipToys
{
    public partial class ProductList 
    {        
        /// <summary>
        /// ProductList control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.ListView ProductList;
    }
}

1 个答案:

答案 0 :(得分:1)

类ProductList也不能包含名为ProductList的字段,属性或方法。请尝试使用以下代码:

public partial class ProductList
{
    /// <summary>
    /// ProductList control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind file.
    /// </remarks>
    protected global::System.Web.UI.WebControls.ListView Products;
}

同样,命名空间不能包含与命名空间同名的类。