Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 809451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:43:56+00:00 2026-05-15T00:43:56+00:00

As it is not possible to override a static class in c#, if i

  • 0

As it is not possible to override a static class in c#, if i want to override a method I generally define a delegate matching the signature of the static method, then modify the method along the lines of:

public static void foo(int bar)
{
  if (delegatename!=null)
  {
   delegatename.Invoke(bar);
  }
  else
  {
   //execute previous code as normal
  }
}

I feel a twinge of guilt, knowing this is a bit messy.

Can anyone suggest a neater solution to this problem (other than rewriting the original structure)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:43:56+00:00Added an answer on May 15, 2026 at 12:43 am

    It seems that you are using the static class as a way to provide a single access point to some resource in your application. If it is the case, you should consider to use an implementation of Singleton design pattern. Doing it, you could take advantage of use inheritance on your non-static classes.

    public abstract class Base { ... }
    
    public class Impl : Base { ... }
    
    public class Singleton : Impl
    { 
        #region Static Members
    
        static readonly Singleton _instance = new Singleton(); 
    
        static Singleton() { } 
    
        static public Singleton Instance 
        { 
            get  { return _instance; } 
        } 
    
        #endregion Static Members
    
        #region Instance Members
    
        private Singleton() { } 
    
        // Method overrides goes here...
    
        #endregion Instance Members
    } 
    

    A deeper discussion on how to implement the singleton design pattern on C# can be found on Implementing the Singleton Pattern in C# article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static method defined in a base class, I want to override
In C# it is not possible to override a static method. Nevertheless I have
Why is it not possible to override static methods? If possible, please use an
This is probably not possible, but I have this class: public class Metadata<DataType> where
I think it's not possible, but I want to make sure.
I have a base class that has an abstract getType() method. I want subclasses
Is it possible to invoke method A.F() from instance of B class except of
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
It is not possible to check out a single file. The finest level of
It is not possible to fire an event in C# that has no handlers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.