0

Base:

public abstract class systemClient : IDisposable
{
    public static List<systemClient> Collection = new List<systemClient>();
    [...]
}

derived class

public class station : systemClient
{
    [...]
}

In this setup I can access station.Collection.

Question is: Is there a way to hide station.Collection ?

dbc
  • 104,963
  • 20
  • 228
  • 340
Mark
  • 419
  • 1
  • 6
  • 21
  • 2
    It would help if you'd show a *real* example. In your example `example` is implicitly private anyway... It would also help if your example followed .NET naming conventions.. – Jon Skeet Aug 14 '14 at 12:37
  • **Static** members are not inherited. It is compiler that allows you to call the static field through the inheriting class, but technically it is incorrect. – Maarten Aug 14 '14 at 12:38
  • 1
    @Maarten judging from (amongst other things) this question http://stackoverflow.com/questions/2281775/c-sharp-static-member-inheritance-why-does-this-exist-at-all it seems this is intended behavioud. That's also backed by the fact that it compiles and runs just fine. – Mark Aug 14 '14 at 13:02
  • 1
    @Mark The answers to your referred question do not make it explicit IMHO. Also, IMHO, it is a compiler trick, and not inheritance, see http://stackoverflow.com/a/2288663/261050. Also, other questions, such as this one, http://stackoverflow.com/questions/4945439/why-is-it-useful-to-access-static-members-through-inherited-types, are not that positive about the 'feature'. – Maarten Aug 14 '14 at 13:23
  • @Maarten more like syntactic saccharin to me. I find that more confusing that useful tbh. – Mark Aug 14 '14 at 13:34

2 Answers2

1

You can't. By creating inhClass as a subclass of baseClass inhClass must provide everything that baseClass provides. Otherwise baseClass x = new inhClass() would be invalid.

In this specific case though you have made the method static, that means that it doesn't actually have its own copy of the method. inhClass is just accessing the static one within baseClass.

Tim B
  • 40,716
  • 16
  • 83
  • 128
  • I thought that was a different story for `static` members, but if I carefully think about it, that wouldn't make sense. – Mark Aug 14 '14 at 12:51
  • Well, it is slightly different... but I'm more of a Java expert than a dot net one so I don't know enough of the specifics on the dot net side to go into them. – Tim B Aug 14 '14 at 12:52
1

I agree with Tim B answer. You can't simply "ignore" some methods or properties of a class which you inherits. But, what you can do is implementing an interface, which may do the work you want. For further reading, take a look here.

Community
  • 1
  • 1
Eminem
  • 870
  • 5
  • 20