Why can't I *override* and *new* a Property (C#) at the same time?

Posted by Tim Lovell-Smith on Stack Overflow See other posts from Stack Overflow or by Tim Lovell-Smith
Published on 2010-03-23T23:01:55Z Indexed on 2010/03/23 23:03 UTC
Read the original article Hit count: 278

Filed under:
|
|
|

According to this question it seems like you can do this for Methods. What I want to know is why it doesn't work when I try it with properties.

public class Foo
{
    public virtual object Value
    {
        get;
        set;
    }
}

public class Foo<T> : Foo
{
    public override object Value
    {
        get
        {
            return base.Value;
        }
        set
        {
            base.Value = (T)value; //inject type-checking on sets
        }
    }

    public new T Value
    {
        get { return (T)base.Value; }
        set { base.Value = value; }
    }
}

Error message from C# 4.0 RC1 Error 1 The type 'ClassLibrary1.Foo' already contains a definition for 'Value' ClassLibrary1\Class1.cs 31 22 ClassLibrary1

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET