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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:28:37+00:00 2026-05-13T20:28:37+00:00

In C#, a superclass’s static members are inherited into the subclasses scope. For instance:

  • 0

In C#, a superclass’s static members are “inherited” into the subclasses scope. For instance:

class A { public static int M() { return 1; } }
class B : A {}
class C : A { public new static int M() { return 2; } }
[...]
A.M(); //returns 1
B.M(); //returns 1 - this is equivalent to A.M()
C.M(); //returns 2 - this is not equivalent to A.M()

Now, you can’t inherit static classes, and the only place I can imagine that static inheritance might matter ignores it entirely: although you can make a generic constraint that requires a type parameter T to be a subclass of A, you still cannot call T.M() (which probably simplifies things for the VM), let alone write a different M implementation in a subclass and use that.

So, the “inheritance” of static members merely looks like namespace pollution; even if you explicitly qualify the name (i.e. B.M) A‘s version is still resolved.

Edit compare with namespaces:

namespace N1{  class X();   }
namespace N1.N2 {  class X();   }
namespace N1.N2.N3 { [...] }

Within N1.N2.N3 It makes sense that if I use X without qualification it refers to N1.N2.X. But if I explicitly refer to N1.N2.N3.X – and no such class exists – I don’t expect it to find N2‘s version; and indeed to compiler reports an error if you try this. By contrast, if I explicitly refer to B.M(), why doesn’t the compiler report an error? After all, there’s no “M” method in “B”…

What purpose does this inheritance have? Can this feature be used constructively somehow?

  • 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-13T20:28:37+00:00Added an answer on May 13, 2026 at 8:28 pm

    So, the “inheritance” of static
    members merely looks like namespace
    pollution

    That’s right, except that one guy’s pollution is another guy’s added spicy flavouring.

    I think Martin Fowler, in his work on DSLs, has suggested using inheritance in this way to allow convenient access to static methods, allowing those methods to be used without class name qualification. So the calling code has to be in a class that inherits the class in which the methods are defined. (I think it’s a rotten idea.)

    In my opinion, static members should not be mixed into a class with a non-static purpose, and the issue you raise here is part of the reason why it’s important not to mix them.

    Hiding private static mutable data inside the implementation of an otherwise “instancey” class is particularly horrible. But then there are static methods, which are even worse mixers. Here’s a typical use of static methods mixed into a class:

    public class Thing
    {
        // typical per-instance stuff
        int _member1;
        protected virtual void Foo() { ... }
        public void Bar() { ... }
    
        // factory method
        public static Thing Make()
        {
            return new Thing();
        }
    }
    

    It’s the static factory method pattern. It’s pointless most of the time, but even worse is that now we have this:

    public class AnotherThing : Thing { }
    

    This now has a static Make method which returns a Thing, not a AnotherThing.

    This kind of mismatch strongly implies that anything with static methods should be sealed. Static members fail to integrate well with inheritance. It makes no sense to have them heritable. So I keep static things in separate static classes, and I gripe about redundantly having to declare every member static when I’ve already said that the class is static.

    But it’s just one of those too-late-now things. All real, working languages (and libraries, and products) have a few of them. C# has remarkably few.

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

Sidebar

Ask A Question

Stats

  • Questions 343k
  • Answers 343k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you tried the new format: i.e. in the form:… May 14, 2026 at 5:20 am
  • Editorial Team
    Editorial Team added an answer The call to Application.ProcessMessages is most likely just needed to… May 14, 2026 at 5:20 am
  • Editorial Team
    Editorial Team added an answer No, you can't redirect to a specific method. You can… May 14, 2026 at 5:20 am

Related Questions

In C# how can you find if an object is an instance of certain
In C# I can do actually this: //This is C# static T SomeMethod<T>() where
I am designing a dashboard to display corporate metrics (currently with ASP.net 3.5 in
In C#, how does one obtain a reference to the base class of a
I've seen usage of Objective-C protocols get used in a fashion such as the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.