Reputation: 6199
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?
Upvotes: 2
Views: 1933
Reputation: 11542
You need to remove virtual
keyword in ProcessorTest
.
override
means "override virtual function", so there is no need to write it again.
Upvotes: 0
Reputation: 14874
remove the virtual here
public class ProcessorTest: Processor
{
public override string SettingsFileName
{
get { return @"C:\Settings.xml"; }
}
}
keywords can not be used together
Upvotes: 4
Reputation: 17631
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
.
Upvotes: 0
Reputation: 2416
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
.
Upvotes: 12