© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
147 replies
MrScautHD

❔ Why can i not override a Method from a class that extend a Interface

public interface IRegistry {
    
    public static readonly List<IRegistry> RegistryTypes = new();

    public virtual void Initialize(ContentManager content) {
        
    }

    public virtual void FixedUpdate() {
        
    }

    public virtual void Draw() {
        
    }
}
public interface IRegistry {
    
    public static readonly List<IRegistry> RegistryTypes = new();

    public virtual void Initialize(ContentManager content) {
        
    }

    public virtual void FixedUpdate() {
        
    }

    public virtual void Draw() {
        
    }
}


public abstract class Registry : IRegistry {

    protected T Register<T, B>(string name, Dictionary<string, B> registryList, T type) where T : B {
        registryList.Add(name, type);
        
        return type;
    }
    
    protected T RegisterLoad<T>(string name, Dictionary<string, T> registryList, ContentManager content, string path) {
        T type = content.Load<T>(path);
        registryList.Add(name, type);

        return type;
    }
}
public abstract class Registry : IRegistry {

    protected T Register<T, B>(string name, Dictionary<string, B> registryList, T type) where T : B {
        registryList.Add(name, type);
        
        return type;
    }
    
    protected T RegisterLoad<T>(string name, Dictionary<string, T> registryList, ContentManager content, string path) {
        T type = content.Load<T>(path);
        registryList.Add(name, type);

        return type;
    }
}


Here i try to override the Method "Initialize" but it does not work, is there a way to override it?
public class ClientFontRegistry : Registry {
    
    // REGISTRY LIST
    public static readonly Dictionary<string, Font> Fonts = new();

    // REGISTRIES
    public static Font Fontoe { get; private set; }
    
    
    public void Initialize(ContentManager content) {
        Fontoe = this.RegisterLoad("fontoe", Fonts, content, "font/fontoe.ttf");
    }
}
public class ClientFontRegistry : Registry {
    
    // REGISTRY LIST
    public static readonly Dictionary<string, Font> Fonts = new();

    // REGISTRIES
    public static Font Fontoe { get; private set; }
    
    
    public void Initialize(ContentManager content) {
        Fontoe = this.RegisterLoad("fontoe", Fonts, content, "font/fontoe.ttf");
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

interface vs extension method vs method in class
C#CC# / help
3y ago
❔ Can i not call a non static Method in a interface?
C#CC# / help
3y ago
❔ Get all Types that extend from my class Entity
C#CC# / help
3y ago