Re: Override static derived variable
- From: "Joanna Carter \(TeamB\)" <joannac@xxxxxxxxxxxxxxx>
- Date: Sun, 19 Jun 2005 18:19:58 +0100
"Chad Z. Hower aka Kudzu" <cpub@xxxxxxxxx> a écrit dans le message de news:
Xns967AC7FE3592Dcpubhowerorg@xxxxxxxxxxxx
> I'll add a bit to Jon's reply since I know you have a Delphi background.
>
> .NET does NOT load a class until it is ACTUALLY used. So the static
constructor for
> a given class will not be called, until the class is actually needed. All
classes are load
> on demand, vs Delphi where the units get their initialization sections
called on start up
> of the application.
Unfortunately, I now understand that bit :-(
But the good news is that I have solved the OP's problem. All you have to do
is to re-declare the GetVar() static method and call the base method !!
class Thing
{
private static string var;
protected static void SetVar(string value)
{
var = value;
}
static Thing()
{
SetVar("Thing");
}
public static string GetVar()
{
return var;
}
}
class Derived : Thing
{
static Derived()
{
SetVar("Derived");
}
public static new string GetVar()
{
return Thing.GetVar();
}
}
Yeeesss !!!
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
.
- Follow-Ups:
- Re: Override static derived variable
- From: knocte
- Re: Override static derived variable
- References:
- Override static derived variable
- From: knocte
- Re: Override static derived variable
- From: Joanna Carter \(TeamB\)
- Re: Override static derived variable
- From: Chad Z. Hower aka Kudzu
- Re: Override static derived variable
- From: Joanna Carter \(TeamB\)
- Re: Override static derived variable
- From: Jon Skeet [C# MVP]
- Re: Override static derived variable
- From: Chad Z. Hower aka Kudzu
- Override static derived variable
- Prev by Date: Re: Override static derived variable
- Next by Date: Re: hotkeys
- Previous by thread: Re: Override static derived variable
- Next by thread: Re: Override static derived variable
- Index(es):
Relevant Pages
|