Static, Sealed, Explicit Interfaces, and new
In this part, we’ll cover three important but often overlooked questions:
- Why are static or sealed methods/classes more efficient?
- What are explicitly implemented interface methods?
- What is the impact of the
newkeyword on a method?
Why are static or sealed methods/classes more efficient?
When you declare a class or method as static or sealed, the runtime knows they cannot be overridden. This means the JIT compiler can optimize method calls — instead of performing a virtual dispatch (vtable lookup), it can emit a direct call.
public class Utils
{
public static int Add(int a, int b) => a + b;
}
public sealed class FinalClass
{
public void Print() => Console.WriteLine("I cannot be derived!");
}
Static methods are always resolved at compile time (no vtable lookup). Sealed classes/methods prevent further overriding, enabling inlining and other optimizations. Takeaway: The less indirection, the faster the method call.
What are explicitly implemented interface methods?
Normally, interface methods are implemented as public members. But sometimes you only want them accessible through the interface type, not the class directly. That’s where explicit implementation comes in.
public interface ILogger
{
void Log(string message);
}
public class FileLogger : ILogger
{
void ILogger.Log(string message)
{
Console.WriteLine($"[File] {message}");
}
}
Usage:
ILogger logger = new FileLogger();
logger.Log("Hello"); // Works
var f = new FileLogger();
// f.Log("Hi"); Compile error
What is the impact of the new keyword on a method?
The new modifier hides a member from the base class. It doesn’t override it (no polymorphism), it just tells the compiler you intentionally want to shadow the base member.
public class Base
{
public void Greet() => Console.WriteLine("Hello from Base");
}
public class Derived : Base
{
public new void Greet() => Console.WriteLine("Hello from Derived");
}
Usage:
Base b = new Derived();
b.Greet(); // Hello from Base
Derived d = new Derived();
d.Greet(); // Hello from Derived
Notice the difference: the base reference calls the base method, even though the object is Derived. This is not polymorphism — it’s method hiding. Takeaway: Use new carefully — it can make code confusing if overused. Prefer override if you want polymorphism.
Final Thoughts
- Static/sealed improve performance by avoiding virtual dispatch.
- Explicit interface implementations give you control over how interfaces are exposed.
- new keyword hides base members but does not override them.
Understanding these mechanics will help you write clearer, more efficient, and less surprising C# code.


