I have A.Test()
declared as public virtual
and B.Test()
declared as private new
.
I'm calling base.Test()
from C
that inherits B
.
This code compiles with Mono 2.10.2 but throws a MethodAccessException
:
class A {
public virtual void Test () { }
}
class B : A {
private new void Test () { }
}
class C : B {
public C ()
{
base.Test ();
}
public static void Main (string[] args)
{
var c = new C ();
}
}
Here is the exception I get:
System.MethodAccessException: Method TestBug.B:Test () is inaccessible from method TestBug.C:.ctor ()
Is this the correct behavior?
Does this compile in Microsoft .NET or with newer versions of Mono?
What does C# spec say about this?
Does it vary with C# version?