I was reading a tutorial about making custom principal, and I've encountered the code:
public class BaseController : Controller
{
protected virtual new UserPrincipal User
{
get { return HttpContext.User as UserPrincipal; }
}
}
How exactly is "protected virtual new" working ?
Keyword "new" is what confuses me the most.
A protected Virtual Machine is a VM that is 'isolated' (in every way possible) from the 'host' and other VMs in a virtualized environment/infrastructure.
You cannot override a non-virtual or static method. The overridden base method must be virtual , abstract , or override . An override declaration cannot change the accessibility of the virtual method. Both the override method and the virtual method must have the same access level modifier.
A virtual method is one that is declared as virtual in the base class. A method is declared as virtual by specifying the keyword "virtual" in the method signature. A virtual method may or may not have a return type. Virtual methods allow subclasses of the type to override the method.
The virtual keyword is used to modify a method, property, indexer, or event declared in the base class and allow it to be overridden in the derived class.
protected
means that it is visible only inside this class and classes derived from it.
virtual
means that it can be overriden in derived classes.
new
means that here you create new overriding hierarchy, i.e. you stop overriding the method defined in the base class and replace it with this method.
More details can be found here
new
is used for member hiding.
Unlike an overridden method, a new
method will not be called by a reference to the base class.
See the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With