Why does a property inherited from an interface become virtual?

As from remarks section of MS docs:

A virtual member may reference instance data in a class and must be referenced through an instance of the class… The common language runtime requires that all methods that implement interface members must be marked as virtual; therefore, the compiler marks the method virtual final

If you need to determine whether this method is overridable then checking IsVirtual is not enough and you need to also check that IsFinal is false.

Here is an extension method that do this check:

public static bool IsOverridable(this MethodInfo method)
    => method.IsVirtual && !method.IsFinal;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)