My mistake: In fact... *the compiler* prevents the overriding of a method
not "explicity" declared as virtual override or abstract. Even when a method
is virtual because of interface implementation.
Sorry for my misunderstandin g (and for my english)
The origin of this question was a "CriticalWarnig " message emitted by
"FxCop" a Microsoft tool for inspect assemblies and its conformande with
..NET guidelines.
The message was: "Constructo rs should not call virtual methods defined by
the class"
With this description: "Virtual methods defined on the class should not be
called from constructors. If a derived class has overridden the method, the
derived class version will be called (before the derived class constructor
is called)."
The inspected assembly in fact was virtual, but generated by the compiler
since its inteface implementation.
Thanks,
Néstor
"Néstor Marcel Sánchez Ahumada" <nm**@terra.c l> wrote in message
news:es******** ******@TK2MSFTN GP09.phx.gbl...
The problem is when the base class is used to implement an Interface: The
methods then are converted to Virtual (ILDAsm shows it, but I can't say
where in the documentation is). Then... there is no way to prevent method
overriding or hiding :S
Néstor
(Hope the english was good)
"Richard A. Lowe" <ch*****@yumspa myumYahoo.com> wrote in message
news:#g******** ******@TK2MSFTN GP11.phx.gbl... There is no benefit confired to a sealed method that does not exist in a
base class method that is not virtual; if allowed, it would be
redundant. In other words this:
public class Base
{
public void MyMethod() { }
}
is no different to a derived class than this:
public class Child : VirtualBase
{
public override sealed MyMethod() { }
}
A derived class can still hide inherited members with the 'new' keyword,
but not override with 'override'.
Richard
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Néstor Marcel Sánchez Ahumada" <nm**@terra.c l> wrote in message
news:Ox******** ******@tk2msftn gp13.phx.gbl... In a method declaration the 'sealed' keyword must be used with the
'override' keyword to avoid further overriding. Thus it can't be used
in base classes. Why?
This would be a good enhancement for C# 3.0?
Any comments?
Néstor