“new” keyword in property declaration in c#

前端 未结 5 1437
忘掉有多难
忘掉有多难 2020-12-01 15:26

I\'ve been given a .net project to maintain. I was just browsing through the code and I noticed this on a property declaration:

public new string navUrl
{
           


        
5条回答
  •  臣服心动
    2020-12-01 15:57

    new is hiding the property.

    It might be like this in your code:

    class base1
    {
        public virtual string navUrl
        {
            get;
            set;
        }
    }
    
    class derived : base1
    {
        public new string navUrl
        {
            get;
            set;
        }
    }
    

    Here in the derived class, the navUrl property is hiding the base class property.

提交回复
热议问题