Re: Override static derived variable



"Chad Z. Hower aka Kudzu" <cpub@xxxxxxxxx> a écrit dans le message de news:
Xns967AC01FEC6FDcpubhowerorg@xxxxxxxxxxxx

> What code are you using to instantiate them? Statics in .NET are not at
all like in Delphi,
> and Im constantly hitting roadblocks here. I understand why they did it
the way they did,
> and it has some advantages but its requires some royal work arounds
sometimes.

Hi Chad

I am not instantiating them for this example, I am just using static calls
as demonstrated by the OP.

Console.WriteLine(Thing.GetVar());
Console.WriteLine(Derived.GetVar());

Both return "Thing", the Derived static constructor doesn't get called at
all if there is a static constructor on the base class. This seems wierd; I
wasn't expecting virtual/override behaviour, just that the static
constructor on Derived would possibly hide that of Thing, but definitely
that it would get executed.

Can an MVP or someone from MS please confirm that this behaviour is
intentional ?

Joanna (Another frustrated Delphi OO expert)

--
Joanna Carter
Consultant Software Engineer


.



Relevant Pages

  • Re: VB 6 -> C# Classes technical note...
    ... Public Not Creatable means that the class interface ... is visible to the clients, but the clients cannot instantiate the class. ... > I know it works using statics just asked for self clarification. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: static constructors not always running when debugging ASP.NET sites.
    ... Are you using attach / detach process during debugging? ... more than one app domain in a process, which is how asp.net can host ... and the statics do not interfere with each ... >2) The static constructor loads custom information from the web.config. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: organization problem
    ... > I have a base64 class that uses a couple of static arrays for encoding ... The catch is statics don't override. ... You can do that in the static constructor of your subclass, ...
    (comp.lang.java.help)

Loading