In C#, virtual
is used when you first declare a property, method, etc. with an implementation that can be overridden. abstract
is similar, but when you declare it without an implementation, so that the deriving class must override it. The syntax for properties is:
public abstract class AbsClass1
{
// non-abstract deriving class MUST override this
public abstract str1 Headers { get; }
}
public class Class1
{
// deriving class may override, but doesn't have to
public virtual str1 Headers { get { return headers; } }
}
(that is, it's applied to the whole property, not the get
)
override
is used when you are overriding something that was previously declared as virtual
. E.g. you might have
public class Class2 : AbsClass1
{
public override str1 Headers { get { return headers; } }
}
See also sealed
and new
.