> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# New Method

The `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

```csharp theme={"dark"}
using System;

public class BaseClass
{
    public void Execute()
    {
        Console.WriteLine("Base implementation");
    }
}

public class DerivedClass : BaseClass
{
    // The 'new' modifier explicitly hides BaseClass.Execute()
    public new void Execute()
    {
        Console.WriteLine("Derived 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.

```csharp theme={"dark"}
using System;

public class Program
{
    public static void Main()
    {
        // Reference type is DerivedClass, Instance type is DerivedClass
        DerivedClass derivedRef = new DerivedClass();
        derivedRef.Execute(); 
        // Output: "Derived implementation"

        // Reference type is BaseClass, Instance type is DerivedClass
        BaseClass baseRef = new DerivedClass();
        baseRef.Execute(); 
        // Output: "Base implementation"
    }
}
```

## 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.

```csharp theme={"dark"}
using System;

public class BaseClass
{
    public virtual void Process() => Console.WriteLine("Base Process");
}

public class DerivedClass : BaseClass
{
    // Hides BaseClass.Process() and starts a new polymorphic chain
    public new virtual void Process() => Console.WriteLine("Derived Process");
}

public class SubDerivedClass : DerivedClass
{
    // Overrides the NEW virtual method in DerivedClass, not BaseClass
    public override void Process() => Console.WriteLine("SubDerived Process");
}
```

## Technical Characteristics

* **Name Resolution vs. Dispatch:** The `new` keyword controls identifier resolution, not dispatch. If a hidden base method was declared as `virtual`, invoking it via a base reference still utilizes dynamic dispatch and consults the original vtable.
* **No Base `virtual` Requirement:** The base class method does not need to be marked as `virtual`, `abstract`, or `override` for a derived class to hide it using `new`.
* **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 `base` keyword (e.g., `base.Execute()`).

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
