Heres my code where im tryng to override SettingsFileName member:
public class ProcessorTest: Processor
{
public virtual override string SettingsFileName
{
get { return @"C:\Settings.xml"; }
}
}
Heres the class where is the member:
public abstract class Processor
{
/// <summary>
/// Implement this property to enable initializing singleton from the correct file path
/// </summary>
public abstract string SettingsFileName { get; }
}
But this gives me a error:
A member 'ProcessorTest.SettingsFileName' marked as override cannot be marked as new or virtual
What am i doing wrong?
Just use override
in the inherited class, not virtual override
.
virtual
marks a member as overridable, so it's used in the base class. override
marks a member as overriding someone overridable. abstract
implies virtual
.
remove the virtual here
public class ProcessorTest: Processor
{
public override string SettingsFileName
{
get { return @"C:\Settings.xml"; }
}
}
keywords can not be used together
As it overrides an abstract Property, SettingsFileName
cannot be virtual.
You cannot use the modifiers new, static, virtual, or abstract to modify an override method.
See MSDN for more information on override
and this article on abstract
.
You need to remove virtual
keyword in ProcessorTest
.
override
means "override virtual function", so there is no need to write it again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.