TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
new modifier in C#, when applied to a method declaration, explicitly hides a member inherited from a base class. This mechanism, known as method hiding or shadowing, instructs the compiler to resolve the method name to the derived class’s implementation rather than the base class’s implementation. It is the syntactically correct way to suppress compiler warning CS0108, which occurs when a derived class member shares a name with a base class member without explicitly stating the intent to hide it.
Unlike the override modifier, which extends an existing polymorphic chain, the new modifier severs the connection to the base class’s implementation for that specific identifier. However, the new modifier only dictates name resolution (scope and visibility); it does not dictate the dispatch mechanism. The method’s binding—whether early (static dispatch) or late (dynamic dispatch)—depends entirely on the presence of the virtual keyword in either the base or the new method declaration.
Syntax and Implementation
Resolution Behavior
Because method hiding relies on the declared reference type for name resolution at compile-time, casting a derived object to its base type will expose the hidden base method.Polymorphic Chain Separation (new virtual)
A critical architectural feature of the new modifier is its ability to be combined with the virtual keyword. Declaring a method as new virtual explicitly hides the base member while simultaneously allocating a new virtual method table (vtable) slot. This initiates a completely new polymorphic chain for subsequent derived classes, independent of the base class’s vtable.
Technical Characteristics
- Name Resolution vs. Dispatch: The
newkeyword controls identifier resolution, not dispatch. If a hidden base method was declared asvirtual, invoking it via a base reference still utilizes dynamic dispatch and consults the original vtable. - No Base
virtualRequirement: The base class method does not need to be marked asvirtual,abstract, oroverridefor a derived class to hide it usingnew. - Signature Matching: To successfully hide a base method, the derived method must have the exact same signature (name and parameters). If the signatures differ, the compiler treats it as standard method overloading rather than method hiding.
- Base Access: The hidden base method remains accessible from within the derived class by using the
basekeyword (e.g.,base.Execute()).
Master C# with Deep Grasping Methodology!Learn More





