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 8062051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:32:19+00:00 2026-06-05T10:32:19+00:00

i have a class that ( right now ) is static: public static class

  • 0

i have a class that (right now) is static:

public static class Grob
{
    public static void Frob()
    {
        Foo.Bar();
    }
}

And that works well. Code calls:

Grob.Frob();

and all is right with the world. Now i want my class to implement an interface:

public static class Grob : IOldNewGrob
{
    public static void Frob()
    {
       Foo.Bar();
    }
}

Unfortunately that does not work, because reasons.

So i would try changing to class to a singleton:

public sealed class Grob
{
   private static volatile Singleton instance;
   private static object syncRoot = new Object();

   private Grob() {}

   public static Singleton Instance
   {
      get 
      { 
         if (instance == null) 
         {
            lock (syncRoot) 
            {
               if (instance == null) 
                  instance = new Singleton();
            }
         }
         return instance;
     }
   }       
}

Which works well enough, except that it doesn’t work – the code no longer compiles:

Grob.Frob();

In other languages it would not be a problem. i would create a global Grob function (called Grob because that’s the name that existing code needs):

function Grob(): GrobSingleton;
{
   return Grob.Instance;
}

//and rename Grob class to something else
public sealed class GrobSinglton
{
   ...
}

except that C# doesn’t have global functions.

In the end:

  • i don’t need a global function
  • i don’t need a static class to be able to implement an interface
  • i don’t need a singleton

i just want it all to work.

  • 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-06-05T10:32:21+00:00Added an answer on June 5, 2026 at 10:32 am

    Why not just create a singleton which also has a static Frob method?

    public sealed class Grob : IOldNewGrob
    {
        private static readonly Grob instance = new Grob();
    
        public static Grob Instance { get { return instance; } }
    
        // Prevent external instantiation
        private Grob() {}
    
        public static void Frob()
        {
            Foo.Bar();
        }
    
        // Implement IOldNewGrob here
    }
    

    You should probably also read my article on implementing the singleton pattern in .NET – there’s really no need to implement the fragile double-checked locking pattern.

    That satisfies both of your requirements of making Grob.Frob() work, and making Grob implement an interface. It’s not clear whether those are your only requirements though – you haven’t really explained why you’re trying to do that – where the singleton or the interface come in.

    EDIT: If the idea was that Frob was a member of IOldNewGrob, you can use explicit interface implementation like this:

    public sealed class Grob : IOldNewGrob
    {
        private static readonly Grob instance = new Grob();
    
        public static Grob Instance { get { return instance; } }
    
        // Prevent external instantiation
        private Grob() {}
    
        public static void Frob()
        {
            // Implementation
        }
    
        // Explicit interface implementation to prevent name collisions
        void IOldNewGrob.Frob()
        {
            // Call the static implementation
            Frob();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create my own NSOpenGLView class, right now the data that i want
I'm writing a website in Silverlight 5 right now. I have a public static
I have class A such that: class A { static int i; A(); f1();
I have a simple game that is in progress. As of right now all
I have a class that looks like this: utils/Result.php <?php class Result { public
I have a method that looks like this public static <T extends MyClass, X
I have a class that looks like the following: Public Class Utilities Public Shared
I have class that represents users. Users are divided into two groups with different
I have a class that implements the IDisposable interface. I am using a webclient
I have a class that is marked with DataContract attributes and I would like

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.